Pymatafirmatacode
Pymatafirmatacode
import time
board = pymata4.Pymata4()
analog_pin =0
digital_pin = 8
board.set_pin_mode_analog_input(analog_pin)
board.set_pin_mode_digital_input(digital_pin)
while True:
value, time_stamp = board.analog_read(analog_pin)
print(value)
time.sleep(1)
MOISTURE SENSOR
try:
from pyfirmata import Arduino,util
except:
import pip
pip.main(["install",'pyfirmata'])
from pyfirmata import Arduino,util
board=Arduino('COM5')
iterator=util.Iterator(board)
iterator.start()
analog_0 = board.get_pin('a:0:i')
print(analog_0.read())
board.exit()
"""
try:
from pyfirmata import Arduino,util
except:
import pip
pip.main(["install",'pyfirmata'])
from pyfirmata import Arduino,util
board=Arduino('COM5')
Moist_pin=0
iterator=util.Iterator(board)
iterator.start()
value=board.analog[Moist_pin].read()
print(value)
"""
import time
import sys
from pymata4 import pymata4
"""
Setup a pin for dht mode
One pin is set for a dht22 and another for dht11
Both polling and callback are being used in this example.
"""
#
POLL_TIME = 5 # number of seconds between polls
def the_callback(data):
"""
A callback function to report data changes.
This will print the pin number, its reported value and
the date and time when the change occurred
if not data[3]:
tlist = time.localtime(data[6])
ftime = f'{tlist.tm_year}-{tlist.tm_mon:02}-{tlist.tm_mday:02} ' \
f'{tlist.tm_hour:02}:{tlist.tm_min:0}:{tlist.tm_sec:02}'
# value = board.dht_read(10)
board = pymata4.Pymata4()
try:
dht(board, the_callback)
except KeyboardInterrupt:
board.shutdown()
sys.exit(0)
import serial
Arduino=serial.Serial('COM5',9600)
while true:
if(Arduino.inWaiting()>0)
myData=Arduino.readline()
print(myData)
import serial
import time
import schedule
#arduino = serial.Serial('COM3',9600)
def dht():
arduino = serial.Serial('COM3',9600);
print("Established serial connection to Arduino")
arduino_data = arduino.readline()
decoded_values = str(arduino_data[0:len(arduino_data)].decode("utf-8"))
list_values = decoded_values.split('x')
arduino_data=0
list_in_floats.clear()
list_values.clear()
#arduino.close()
print('Connection closed')
print('<---------------->')
#MAIN CODE
list_values = []
list_in_floats = []
print('Program started')
schedule.every(5).seconds.do(dht)
while True:
schedule.run_pending()
#time.sleep(1)
LDR SENSOR
void setup() {
void loop()
{
if (Serial.available()) //loop to operate motor
{
int speed = Serial.parseInt(); // to read the number entered as text in the
Serial Monitor
if (speed >= 0 && speed <= 255)
{
analogWrite(WATERPUMP, speed);// tuns on the motor at specified speed
}
}
val = digitalRead(8); //Read data from soil moisture sensor
if(val == LOW)
{
digitalWrite(13,LOW); //if soil moisture sensor provides LOW value send LOW value
to motor pump and motor pump goes off
}
else
{
digitalWrite(13,HIGH); //if soil moisture sensor provides HIGH value send HIGH
value to motor pump and motor pump get on
}
delay(400); //Wait for few second and then continue the loop.
}
WIFI
"""
Copyright (c) 2020 Alan Yorinks All rights reserved.
You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
import sys
import time
"""
This program tests an ESP-8266 using StandardFirmataWiFi.
It will toggle the on-board LED 4 times.
# some globals
DIGITAL_PIN = 16 # arduino pin number
IP_ADDRESS = "192.168.2.189"
IP_PORT = 3030
my_board.shutdown()
import logging
import sys, serial
from time import *
import datetime, string
def enum(**enums):
return type('Enum', (), enums)
for i in range(retry):
ser.flushInput()
ser.write( sCmd + "\r\n" )
ret = ser.readline() # Eat echo of command.
sleep( 0.2 )
while( lp < waitTm or 'busy' in ret):
while( ser.inWaiting() ):
ret = ser.readline().strip( "\r\n" )
logging.debug( ret )
lp = 0
if( ret in Status.OK ): break
#if( ret == 'ready' ): break
if( ret == Status.ERR ): break
sleep( 1 )
lp += 1
sleep(1)
if( ret in Status.OK ): break
logging.info( "Command result: %s" % ret )
return ret
if len(sys.argv) != 5:
print "Usage: esp8266test.py port baud_rate ssid password"
sys.exit()
port = sys.argv[1]
#Baud rate should be: 9600 or 115200
speed = sys.argv[2]
ssid = sys.argv[3]
pwd = sys.argv[4]
ser = serial.Serial(port,speed)
if ser.isOpen():
ser.close()
ser.open()
ser.isOpen()
send_cmd( "AT" )
# send_cmd( "AT+RST", 5 ) # NOTE: seems to cause problems that require manually
reset (pulling down the RST pin)
# sleep(3)
send_cmd( "AT+CWMODE=1" ) # set device mode (1=client, 2=AP, 3=both)
#The mode will be changed on Olimex MOD-WIFI-ESP8266-DEV only after a reset
#The command below will reset the device
send_cmd( "AT+RST");
send_cmd( "AT+CWLAP", 10) # scan for WiFi hotspots
send_cmd( "AT+CWJAP=\""+ssid+"\",\""+pwd+"\"", 5 ) # connect
addr = send_cmd( "AT+CIFSR", 5) # check IP address
ser.close()