In the last Blogs, I have already mentioned somewhat details of what I am going to do for this 1m3Pi Challange,
I loved working on the MQTT protocol. There are two BME280 sensors that are sending data with ESPs.
For the debugging purpose, I wanted to have all the sensors data on the LCD screen, which also looks nicer if
I would make it somewhat fancier.
Nevertheless, I also tried to start both LCDs together but the LCD on the Enviro Hat isn't starting. The problem could be
in SPI interface lines only, as I could see the backlight is turning on.
I took reference, of how to do this from one of the other challengers who has done it successfully.
In my code, I have the following connection as the LCD object uses the same to be created.!!
No problem, I will work it out!!
- #Enviro LCD
- dispEnviro = ST7735.ST7735(
- port = 0,
- cs = 0, #GPIO 8
- dc = 9,
- backlight=25,
- rotation=270,
- spi_speed_hz=10000000
- )
- #Automation HAT Mini LCD
- dispAutomation = ST7735.ST7735(
- port = 0,
- cs = 1, #GPIO 7
- dc = 9,
- backlight=12,
- rotation=270,
- spi_speed_hz=10000000
- )
For the image manipulation and all the settings to be displayed, one can look at the python module such as ImageDraw.
ImageDraw has many things.
There are many things in the Python code I have currently but I would explain them. I have 6 callback functions for
MQTT ESP modules to subscribe to them from RPI to get the sensor data. I use loop_start() and stop() to subscribe
for a limited amount of time. I would disconnect from the publishers and then, I have a code to get data from the sensors
connected to the RPI.
Once I have all the required data I write a code to display the data on the LCD.
#!/usr/bin/env python3 import os import sys import time import bme280 import smbus2 from ltr559 import LTR559 sys.path.append(os.path.abspath("/home/pi/1m3pi/MqTT.py")) sys.path.append(os.path.abspath("/home/pi/1m3pi/Disp.py")) from Disp import * from MqTT import * import DPS dps310 = DPS.DPS() ser_add = '192.168.43.71' Wemos_temp = '/home/top/temperature' Wemos_humy = '/home/top/humidity' Esp_temp = 'ESP8266_temp' Esp_humy = 'ESP8266_humy' mqtt_user ='ujjval' mqtt_pass ='' esp_t=0.00 wemos_t=0.00 ltr559 = LTR559() port = 1 address = 0x76 bus = smbus2.SMBus(port) cal_par = bme280.load_calibration_params(bus, address) def on_connect(wemos_client, userdata, flags, rc): #print('connected with code' + str(rc)) wemos_client.subscribe((Wemos_temp,0)) wemos_client.subscribe((Wemos_humy,0)) def on_connect1(esp_client, userdata, flags, rc): #print('connected with code' + str(rc)) esp_client.subscribe((Esp_temp,0)) esp_client.subscribe((Esp_humy,0)) def on_message(wemos_client, userdata, msg): payload = msg.payload print(msg.topic) wemos_t= float(payload) print(float(payload)) def on_message1(esp_client, userdata, msg): payload = msg.payload print(msg.topic) esp_t =msg.payload print(float(payload)) return esp_t #on_message1.esp_t=float(payload) def on_disconnect(self, wemos_client, userdata, rc): self.disconnected.set_result(rc) def on_disconnect1(self, esp_client, userdata, rc): self.disconnected.set_result(rc) def get_remote_temp(): wemos_client = mqtt.Client() wemos_client.username_pw_set(mqtt_user, mqtt_pass) wemos_client.on_connect = on_connect wemos_client.on_message = on_message wemos_client.on_disconnect = on_disconnect wemos_client.loop_start() wemos_client.connect(ser_add, 1883) sleep(2) wemos_client.loop_stop() esp_client = mqtt.Client() esp_client.username_pw_set(mqtt_user, mqtt_pass) esp_client.on_connect = on_connect1 esp_client.on_message = on_message1 esp_client.on_disconnect =on_disconnect1 esp_client.loop_start() esp_client.connect(ser_add, 1883) sleep(2) esp_client.loop_stop() print("Wemos Temperature ", wemos_t) def main(): while True: data = bme280.sample(bus, address, cal_par) print("Temprature",data.temperature) print("Humidity", data.humidity) print("Now printing the LTR sensor data....") ltr559.update_sensor() lux = ltr559.get_lux() prox = ltr559.get_proximity() print("Lux ", lux, "Proximity ", prox) scaled_p = dps310.calcScaledPressure() scaled_t = dps310.calcScaledTemperature() p = dps310.calcCompPressure(scaled_p, scaled_t) t = dps310.calcCompTemperature(scaled_t) print("Temprature", t) print("Dsp_press", p) get_remote_temp() print("ESP8266temprature", esp_t) colour = (255, 181, 86) font = ImageFont.truetype(UserFont, 12) bar_height = disp1.height bar_width = disp1.width img=Image.new('RGB',(bar_width, bar_height), color=(0,0,0)) draw = ImageDraw.Draw(img) rect_color =(0,180,180) draw.rectangle((0,0,160,80), rect_color) font_size = 18 #font = ImageFont.truetype("fonts/Asap/Asap-Bold.ttf", font_size) colour=(255,255,255) temp="T1: {:.2f} *C".format(data.temperature) humy="H1: {:.2f} %".format(data.humidity) lux = "Lux: {:.2f} ".format(lux) dsp_temp = "T2: {:.2f} ".format(t) esp_temp ="T3: {:.2f} ".format(esp_t) draw.text((0,0), temp, font=font, fill=colour) draw.text((0,10),humy, font=font, fill=colour) draw.text((0,20),lux, font=font, fill=colour) draw.text((0,30),dsp_temp, font=font, fill=colour) draw.text((0,40),esp_temp, font=font, fill=colour) disp.display(img) disp1.display(img) sleep(1) if __name__ == "__main__": main()
The next things are to connect the RGB LEDs which I have bought and making a box fitting which I have already planned
I also might add some more sensors to have more control over the plant cultivation and study in space. The inspiration for
connecting so many sensors was from the article which I read and which mentioned that the plant chamber in space uses
around approx 180 kinds of different sensors including IR cameras to have vision during nights.
For the ON/OFF of LED's, I will use for sure the 24V relay connection of the Automation HaT. But the current rating is only
2Amps which is lesser than required to turn on LED's. For LEDs approximately 5V & 7.2A is required.
The solution could be to use one of the ESP module and a relay connection to turn on the LEDs. When I started working on MQTT
for this project, I was not sure that there is internet on ISS, as MQTT is an internet-based protocol. but now I have confirmed that
there is very good internet than normally in our homes.