element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
1 Meter of Pi
  • Challenges & Projects
  • Design Challenges
  • 1 Meter of Pi
  • More
  • Cancel
1 Meter of Pi
Blog Blog-5 Collecting sensor data for 1m3 of Pi Space
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: embeddedguy
  • Date Created: 29 Dec 2020 3:05 PM Date Created
  • Views 561 views
  • Likes 3 likes
  • Comments 0 comments
  • 1m3pi
Related
Recommended

Blog-5 Collecting sensor data for 1m3 of Pi Space

embeddedguy
embeddedguy
29 Dec 2020

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!!

 

  1. #Enviro LCD
  2. dispEnviro = ST7735.ST7735( 
  3.      port = 0, 
  4.      cs = 0, #GPIO 8
  5.      dc = 9, 
  6.      backlight=25, 
  7.      rotation=270, 
  8.      spi_speed_hz=10000000
  9. ) 
  10. #Automation HAT Mini LCD
  11. dispAutomation = ST7735.ST7735( 
  12.      port = 0, 
  13.      cs = 1, #GPIO 7
  14.      dc = 9, 
  15.      backlight=12, 
  16.      rotation=270, 
  17.      spi_speed_hz=10000000
  18. ) 

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.

 

imageimage

image

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.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Finally, I am happy!!
image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube