Wen-Liang Lin
Published © GPL3+

Ethernet-GridEYE(AM8833)

Usin W5100S-EVB-Pico reading AM8833 and send by UDP.

IntermediateFull instructions provided1 hour73
Ethernet-GridEYE(AM8833)

Things used in this project

Hardware components

W5100S-EVB-Pico
WIZnet W5100S-EVB-Pico
×1
SparkFun Grid-EYE Infrared Array Breakout
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

wire connect

Code

Ethernet-GridEYE.ino

Arduino
/*
   modify from
   example
   Ethernet - UDPSendReceiveString

   and

   Adafruit AMG88xx - pixels_test


*/

/*
  UDPSendReceiveString

  This sketch receives UDP message strings, prints them to the serial port
  and sends an "acknowledge" string back to the sender

  A Processing sketch is included at the end of file that can be used to send
  and receive messages for testing with a computer.

  created 21 Aug 2010
  by Michael Margolis

  This code is in the public domain.
*/
/***************************************************************************
  This is a library for the AMG88xx GridEYE 8x8 IR camera

  This sketch tries to read the pixels from the sensor

  Designed specifically to work with the Adafruit AMG88 breakout
  ----> http://www.adafruit.com/products/3538

  These sensors use I2C to communicate. The device's I2C address is 0x69

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Dean Miller for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

/*
  AMG88xx
*/
#include <Wire.h>
#include <Adafruit_AMG88xx.h>
Adafruit_AMG88xx amg;
float pixels[AMG88xx_PIXEL_ARRAY_SIZE];

/*
   Ethernet
*/
#include <Ethernet.h>
#include <EthernetUdp.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 137, 200);//the IP address is dependent on your network
IPAddress dnsServer(192, 168, 137, 1);// the dns server ip
IPAddress gateway(192, 168, 137, 1);// the router's gateway address:
IPAddress subnet(255, 255, 255, 0);// the subnet:
unsigned int localPort = 8888;      // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,
char ReplyBuffer[1000];        // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

/*
   this project use
*/
bool measure_state = 0;
String Sendbuf;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  //  while (!Serial) {
  //    ; // wait for serial port to connect. Needed for native USB port only
  //  }
  Serial.println("Start Serial");

  Wire1.setSDA(2);
  Wire1.setSCL(3);
  Wire1.begin();
  Serial.println(F("AMG88xx pixels"));
  bool status;
  // default settings
  status = amg.begin(AMG88xx_ADDRESS, &Wire1);
  if (!status) {
    Serial.println("Could not find a valid AMG88xx sensor, check wiring!");
  }

  // You can use Ethernet.init(pin) to configure the CS pin
  Ethernet.init(17);  // W5100S-EVB-Pico
  // start the Ethernet
  Ethernet.begin(mac, ip, dnsServer, gateway, subnet);


  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    Serial.println(Ethernet.hardwareStatus());
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  //print out the IP address
  Serial.print("IP = ");
  Serial.println(Ethernet.localIP());

  Serial.print("Port = ");
  Serial.println(localPort);

  // start UDP
  Udp.begin(localPort);
  IPAddress remote = Udp.remoteIP();
  Serial.println("connect with UDP and send \"start\" ");
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    // Serial.print("Received packet of size ");
    // Serial.println(packetSize);
    // Serial.print("From ");

    // read the packet into packetBuffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    // Serial.println("Contents:");
    Serial.println(packetBuffer);
    if (strcmp(packetBuffer, "start") == 0) //start commend
    {
      Serial.println("start!");
      measure_state = 1;
    }
    else if (strcmp(packetBuffer, "stop") == 0) //stop commend
    {
      Serial.println("stop!");
      measure_state = 0;
    }
    memset(packetBuffer, 0, sizeof(packetBuffer));

  }

  if (measure_state)
  {
    amg.readPixels(pixels);
    Sendbuf = "";
    for (int i = 1; i <= AMG88xx_PIXEL_ARRAY_SIZE; i++) {
      String j = "";
      Sendbuf += String(pixels[i - 1]);
      if (i < AMG88xx_PIXEL_ARRAY_SIZE)
      {
        Sendbuf += ", ";
      }

    }
    //    Sendbuf += ", 55555"; //magic number
    //    Serial.println(Sendbuf.length());
    Sendbuf.toCharArray(ReplyBuffer, 1000);
    Serial.println(ReplyBuffer);

    // send a reply to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
//    Serial.print("IP = ");
//    Serial.println(Udp.remoteIP());
//
//    Serial.print("Port = ");
//    Serial.println(Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();

  }

  delay(100);
}

Ethernet-GridEYE qt6.py

Python
import numpy as np

from PyQt6 import QtWidgets
from PyQt6.QtGui import *
from PyQt6.QtCore import *

import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas

import sys
import socket

HOST = '192.168.137.200'
PORT = 8888
server_addr = (HOST, PORT)
class GridEYE(QtWidgets.QWidget):

    def __init__(self):
        super().__init__()

        self.setWindowTitle('Grid EYE')
        self.resize(640, 480)
        self.t = 0
        self.ui()

    def ui(self):
        self.canvas = FigureCanvas(self.heatmap())

        self.graphicview = QtWidgets.QGraphicsView(self)
        self.graphicview.setGeometry(0, 0, 640, 480)

        self.graphicscene = QtWidgets.QGraphicsScene()
        self.graphicscene.setSceneRect(0, 0, 620, 460)
        self.graphicscene.addWidget(self.canvas)

        self.graphicview.setScene(self.graphicscene)

    def heatmap(self):
        fig = plt.figure(figsize=(6,4), dpi=100)
        client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        client_socket.settimeout(0.15)
        message = b'start'
        client_socket.sendto(message, server_addr)
        try:
            data, server = client_socket.recvfrom(1024)
            data = data.decode('utf-8')
            string_data = data.split(',')
            array = np.array(string_data,dtype=np.float32)
            # array = np.delete(array, -1)
            mx = array.reshape((8,8))
            # plt.imshow(mx, vmin=array.min(), vmax=array.max(),cmap='hot', interpolation='bicubic')
            plt.imshow(mx,cmap='hot', interpolation='bessel')
            # plt.show()

        except socket.timeout:
            print('REQUEST TIMED OUT')
        
        plt.close()
        return fig

    def count(self):
        self.canvas = FigureCanvas(self.heatmap())
        self.graphicscene.clear()
        self.graphicscene.addWidget(self.canvas)
if __name__ == '__main__':
    
    app = QtWidgets.QApplication(sys.argv)
    Form = GridEYE()
    Form.show()

    timer = QTimer()
    timer.timeout.connect(Form.count)
    timer.start(5)
    app.exec()
    
    client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    message = b'stop'
    client_socket.sendto(message, server_addr)
    client_socket.close()
    sys.exit()
    

Ethernet-GridEYE.py

Python
import numpy as np
import matplotlib.pyplot as plt
import socket
HOST = '192.168.137.200'
PORT = 8888
server_addr = (HOST, PORT)


for pings in range(10):
    client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    client_socket.settimeout(0.15)
    message = b'start'
    addr = (HOST, 8888)

    client_socket.sendto(message, addr)
    try:
        data, server = client_socket.recvfrom(1024)
        data = data.decode('utf-8')
        string_data = data.split(',')
        array = np.array(string_data,dtype=np.float32)
        # array = np.delete(array, -1) #pop magic number
        mx = array.reshape((8,8))
        # plt.imshow(mx, vmin=array.min(), vmax=array.max(),cmap='hot', interpolation='bicubic')
        plt.imshow(mx,cmap='hot', interpolation='bicubic')
        plt.savefig(f'myimage{pings}.png')
        # plt.show()
 
    
    except socket.timeout:
        print('REQUEST TIMED OUT')

Credits

Wen-Liang Lin
29 projects • 35 followers
Hi, I am momososo

Comments