Yue YiJerrick KengYi JieJon Tan
Published

Our Automated Fish Maid

Our aim is to minimise manpower needed by making use of the M5 stack devices to create a fish farm where most things are automated.

BeginnerShowcase (no instructions)98
Our Automated Fish Maid

Things used in this project

Story

Read more

Schematics

Blockly Transmit

Blockly Receive

Code

Receive

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.PORTA)
rgb_7 = unit.get(unit.RGB, 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 == 'Turn Off Motor':
    servo0.write_angle(0)
    wait(1)
  elif Data_send == 'Turn On RGB':
    rgb_7.setColorAll(0xffffff)
    rgb_7.setBrightness(100)
    wait(1)
  elif Data_send == 'Turn Off RGB':
    rgb_7.setBrightness(0)
    wait(1)

  pass
espnow.recv_cb(recv_cb)



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

Transmit

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

setScreenColor(0x222222)
env3_0 = unit.get(unit.ENV3, unit.PAHUB0)
light_0 = unit.get(unit.LIGHT, unit.PORTB)
tof_0 = unit.get(unit.TOF, unit.PAHUB1)


Data_send = None

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

label6 = M5TextBox(10, 68, "label 6", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label7 = M5TextBox(10, 146, "label 7", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label8 = M5TextBox(8, 213, "label 8", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label0 = M5TextBox(10, 46, "Water Temperature:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(174, 46, "label 1", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(10, 122, "Water Level:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(113, 122, "label 3", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(10, 195, "Water clarity:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(113, 195, "label 5", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label9 = M5TextBox(10, 0, "label 9", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label10 = M5TextBox(11, 19, "label 10", lcd.FONT_Default, 0xFFFFFF, rotate=0)


# Describe this function...
def Output():
  global Data_send
  if btnA.wasPressed():
    Data_send = 'Turn On RGB'
    label9.setText(str(Data_send))
    espnow.send(id=1, data=str('Turn On RGB'))
    wait(3)
  elif btnA.pressFor(0.8):
    Data_send = 'Turn Off RGB'
    label9.setText(str(Data_send))
    espnow.send(id=1, data=str('Turn Off RGB'))
    wait(3)
  elif btnB.wasPressed():
    Data_send = 'Turn On Motor'
    label9.setText(str(Data_send))
    espnow.send(id=1, data=str('Turn On Motor'))
    wait(3)
  elif btnB.pressFor(0.8):
    Data_send = 'Turn Off Motor'
    espnow.send(id=1, data=str('Turn Off Motor'))
    label9.setText(str(Data_send))
    wait(3)

# Describe this function...
def water_level():
  global Data_send
  if (tof_0.distance) / 1000 >= 1:
    label3.setText(str((tof_0.distance) / 1000))
    label7.setText('Water level is normal')
  elif (tof_0.distance) / 1000 < 1:
    label3.setText(str((tof_0.distance) / 1000))
    label7.setText('Water level is abnormal, please check ')

# Describe this function...
def water_temp():
  global Data_send
  label1.setText(str(env3_0.temperature))
  if (env3_0.temperature) < 25:
    label6.setText('Temperature is lower than usual')
  elif (env3_0.temperature) > 27:
    label6.setText('Temperature is not normal')
  else:
    label6.setText('Temperature is normal')

# Describe this function...
def water_clarity():
  global Data_send
  label5.setText(str(light_0.digitalValue))
  if (light_0.digitalValue) == 1:
    label8.setText('Water is clear')
  else:
    label8.setText('Water is not clear, please turn on water pump')



def send_cb(flag):
  global Data_send
  Data_send = flag
  label10.setText('Yes')

  pass
espnow.send_cb(send_cb)



espnow.add_peer('78:21:84:93:b3:09', id=1)
while True:
  Output()
  water_temp()
  water_clarity()
  water_level()
  wait_ms(2)

Credits

Yue Yi
1 project • 0 followers
Contact
Jerrick Keng
1 project • 0 followers
Contact
Yi Jie
1 project • 0 followers
Contact
Jon Tan
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.