Yashvi ShahQi YunDaryl CheongMay Thu Khin (Haru)
Published

Group 5 FlourishTech EEP project

Imagine fixing all your hydroponics solutions with a simple M5 stack

IntermediateFull instructions provided161
Group 5 FlourishTech EEP project

Things used in this project

Story

Read more

Code

Code for the second M5

Python
from m5stack import *
from m5ui import *
from uiflow import *
import espnow
import wifiCfg
import time
import unit

setScreenColor(0x222222)
servo0 = unit.get(unit.SERVO, unit.PORTB)


mac = None
Data_send = None

wifiCfg.wlan_ap.active(True)
wifiCfg.wlan_sta.active(True)
espnow.init()

label0 = M5TextBox(155, 49, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(170, 125, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
title0 = M5Title(title="DataReceive", x=3, fgcolor=0xFFFFFF, bgcolor=0xff0047)
label2 = M5TextBox(5, 49, "Mac Address:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(5, 125, "Data Received:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)




def recv_cb(_):
  global mac,Data_send
  mac, _, Data_send = espnow.recv_data(encoder='str')
  label1.setText(str(Data_send))
  if Data_send == 'Turn on Motor':
    servo0.write_angle(180)
    wait(1)
  elif Data_send == 'Stop Motor':
    servo0.write_angle(0)
    wait(1)

  pass
espnow.recv_cb(recv_cb)



label0.setText(str(espnow.get_mac_addr()))

Code for the first M5

Python
from m5stack import *
from m5ui import *
from uiflow import *
import espnow
import wifiCfg
import time
import unit

setScreenColor(0x222222)
env2_1 = unit.get(unit.ENV2, unit.PORTA)
light_1 = unit.get(unit.LIGHT, unit.PORTB)
pbhub_3 = unit.get(unit.PBHUB, unit.PORTA)
earth_1 = unit.get(unit.EARTH, unit.PORTB)


Data_send = None

wifiCfg.wlan_ap.active(True)
wifiCfg.wlan_sta.active(True)
espnow.init()

label0 = M5TextBox(156, 39, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label1 = M5TextBox(122, 65, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label2 = M5TextBox(12, 39, "Sending data:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label3 = M5TextBox(12, 65, "Data Sent:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label4 = M5TextBox(122, 174, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label5 = M5TextBox(78, 121, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label6 = M5TextBox(146, 148, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label7 = M5TextBox(12, 148, "Temperatue:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label10 = M5TextBox(12, 174, "Humidity:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label8 = M5TextBox(12, 121, "Light:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)




espnow.add_peer('78:21:84:93:b2:b5', id=1)
label0.setText(str(Data_send))
while True:
  if (env2_1.temperature) > 30:
    Data_send = 'Turn on Motor'
    label0.setText(str(Data_send))
    espnow.send(id=1, data=str('Turn on Motor'))
    wait(3)
  else:
    espnow.send(id=1, data=str('Stop Motor'))
    label0.setText(str(Data_send))
    wait(3)
  if (env2_1.humidity) < 20:
    Data_send = 'Turn on Motor'
    label0.setText(str(Data_send))
    espnow.send(id=1, data=str('Turn on Motor'))
    wait(3)
  else:
    espnow.send(id=1, data=str('Stop Motor'))
    label0.setText(str(Data_send))
    wait(3)
  if (light_1.analogValue) < 100:
    espnow.send(id=1, data=str('Turn on Motor'))
    label0.setText(str(Data_send))
    wait(3)
  else:
    espnow.send(id=1, data=str('Stop Motor'))
    label0.setText(str(Data_send))
    wait(3)
  wait_ms(2)

Credits

Yashvi Shah
1 project • 1 follower
Qi Yun
1 project • 1 follower
Daryl Cheong
1 project • 0 followers
May Thu Khin (Haru)
1 project • 1 follower

Comments