Python Forum
Exceeding the value - turn on the relay.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exceeding the value - turn on the relay.
#1
Good afternoon, I can’t figure out how to write the code. We read the value from the database, if it exceeds, say, 2000, then we turn on the relay via GPIO.

How to read - I understood.
import struct
import sys
import time
import datetime
import pymysql.cursors
import wiringpi
from wiringpi import GPIO

connection = pymysql.connect(host='127.0.0.1', user='root', password='2548695542', db='sd', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)

with connection:
    cur = connection.cursor()
    cur.execute("SELECT * FROM ddd1 ORDER BY id DESC LIMIT 1")
    rows = cur.fetchall()

    for row in rows:
        print(row["weight"])
How to turn on the relay - too.
NUM2 = 2    # (wPi-2) orange pi zero 2

wiringpi.wiringPiSetup()

wiringpi.pinMode(NUM2, wiringpi.GPIO.OUTPUT);

wiringpi.digitalWrite(NUM2, GPIO.HIGH);
But I can’t figure out how to connect this together. :-(
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  gpiozero button turn off LED that is already on duckredbeard 3 882 Dec-11-2024, 06:23 PM
Last Post: duckredbeard
  How do i turn my program into a .exe julio2000 1 2,540 Feb-14-2020, 08:18 PM
Last Post: snippsat
  Turn py into exe tester21 4 4,222 Jul-22-2019, 04:31 PM
Last Post: nilamo
  Not sure how to turn this into a loop iamgonge 1 2,667 Dec-05-2018, 11:03 PM
Last Post: anandoracledba
  Relay switches On and Off every cylcle... hotwalk 6 4,811 Nov-29-2017, 05:50 PM
Last Post: hotwalk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020