more backup notes for a bad memory - - -
(Not finished but working)
Using an Arduino UNO with colour LCD display connected to Raspberry Pi by ESP8266 WIFI
Objective
Display home network IOT information on LCD connected to a Raspberry Pi by WIFI
Raspberry Pi Blassic control program
Three thermistors on an Arduino Nano in the greenhouse connect to the Pi by i2c
A string of bytes is assembled in uno_data$ and saved to ramdisk in file uno_data.txt
A high and a low byte for each of three thermisters.
nc -u -w 3 192.168.0.180 9999 < /var/www/ramdisk/uno_data.txt in the Pi grabs uno_data.txt and sends the data to ESP8266
I find that a byte 0 (NULL character) in the string sent to the ESP causes the transmission to stop
So I add 1 to the high byte at the Pi end and subtract it in the UNO (the maximum integer I need is 1024)
#!/usr/sbin/blassic ' /home/graham/housekeeping/stringsforUNOESP2.bas ' i2c address 4 to get data PAUSE 4000 OPEN "/var/www/ramdisk/from_arduino0.dat" FOR INPUT AS #1:INPUT #1,arduino_byte_0$:CLOSE #1 PRINT "arduino_byte_0$ for screen = ",arduino_byte_0$ in1 = 2 PRINT in1 uno_data$ = chr$(in1) + chr$(in3) + chr$(in2) + chr$(in5) + chr$(in4) + chr$(in7) + chr$(in6) OPEN "/var/www/ramdisk/uno_data.txt" FOR OUTPUT AS #1:PRINT #1,uno_data$:CLOSE #1 SHELL "nc -u -w 3 192.168.0.180 9999 < /var/www/ramdisk/uno_data.txt" SYSTEM |
ESP8266 program to receive UDP data from Pi and send it to the UNO via serial
Serial.println(packetBuffer) sends the string to the UNO
and to a CoolTerm serial monitor in the iMac for testing via serial to USB
port.write sends data to the Pi via WIFI
#include <ESP8266WiFi.h> WiFiUDP port; char packetBuffer[255]; void setup() { IPAddress ip(192, 168, 0, 180); port.begin(localPort); } //Note - Serial.write(packetBuffer); also has trouble understanding null string port.write("Your UDP packet was received OK\r\n"); |
The UNO program that receives the serial data string and displays the data on the LCD
#define LCD_RESET 10 // NB! to avoid i2c pin A4 - rewire the board A4 to D10 // Assign human-readable names to some common 16-bit color values: Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //int command = 0; //=====================================================================================================setup START pinMode(13, OUTPUT); Flash_LED_13(); //show we are alive unsigned long DriveLCD() { tft.setTextSize(3); tft.setCursor(2, 122); tft.setTextColor(BLUE); // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FUNCTION Flash_LED_13 |
Test circuit
The ESP uses 3.3 volts and the UNO uses 5 volts.
To reprogram the UNO it is necessary to disconnect the serial wires from the voltage level converter
Please email me if you want to swap notes