Raspberry pi relay 3 delay commands - python

I'm new to raspberry pi and python coding. I've been practicing how to interface the relay to raspberry pi for our project. The project should include 3 delays for the relay, 1 for 9 seconds, 1 for 1 hour (3600 seconds), and another 1 for 24 days (2,073,600 seconds).
I managed to find a code that's good for the 1st 2 actions I need but I'm afraid that adding the 3rd one might ruin the program. Any tips? sorry for my bad English.
Here is my code

I think for 24 days delay, it is better to connect an RTC to your Raspberry Pi.
The RTC will keep record of the day,month,year and time. Raspberry pi will read the data and work accordingly.

Related

Power Meter - Modbus RS485 - After 5 to 6 hours, the device doesn't answer anymore

Using a Raspberry PI, I've written a loop in Python reading 6 registers of a Polier MTR5LMOD, every 15 sec, using the waveshare 2-ch rs485 hat.
The program works during 5 to 6 hours (sometime less, sometime more)... and suddenly... the device doesn't answer any more (no response) !
I reboot the system / I reboot the Polier... but nothing changes.
To test further I used modpoll to successfully check comms. I launch my program, it works for 5 to 6 hours. Then the device doesn't answer. I reuse modpoll and the device doesn't answer. After leaving everything overnight both modpoll and my program both work again.
I tried different libraries : UMODBUS or MinimalModBus Or PyModBus.
I've checked several time my wiring and hardware : the cable is less than 10m, with resistance in both sides of 120 Ohms.
The device restart sometimes, like the day after, but no action was taken...
Has anybody faced such situation and found its root cause?
There are a few possible reasons,
Polling too fast leads to flow control or overflow on device
Device goes to sleep mode
The baud rate changed due to crystal/quartz phase shifting
You could try serial port monitoring tools to debug the underlying communication, check what happens exactly during the abnormal period.

Problems with raspberry pi and python

I have 2 questions.
1º - I have a raspberry pi that has connected to itself a ultrasonic sensor, a rfid reader and a pi camera. The problem I'm facing is that after like 10 reads of the rfid reader, it starts reading really slow ( takes probably 10 seconds to read 1 card ) or even stops reading.
2º - I would like to aplly interrupts in the devices mentioned above, but I dont know how to do it even though I have been searching a lot about this.
Does anybody knows why is this happening?

Remote connection between Raspberry pi and other computer through python over internet on real time

I want a help in robotics stuff..
My Question is ... :
How to connect my robotic car ( car is having raspberry pi as controller) with my computer via internet .. so the I can control the car from my computer's keybord..
Previously i was using VNC and made a python tkinter script (stored at raspberry pi) and by the help of vnc i control the car but it was not good ..
Most of the time the when i press the key, function works after sometime and worst thing was that it stores all the commands in a queue or buffer ..
So realtime operation was not happenping ( like: if i press forward arrow key for 2 seconds, it evoked moveForward() 20 times which is equal to 2 meters forward move and takes 4 seconds to travel .. BUT after that if i press right arrow key then it evokes moveRight() .. the worst part is it will execute after finishing the moveForward() stored in a queue i.e after 4 seconds .. and not on real time)
Is there any way to control/give command to raspberry pi on real time and not in a queue manner via socketing or other thing ?
note : i have a static ip address with specific port open and it has to be done over internet.
The appearance of your car might mainly relate to the whole system response time. The Raspberry Pi may be not fast enough. If there is no necessary, analog signal may on real time.

How to use multiple Arduino boards with a single Raspberry Pi for sending and receiving data?

I am doing a project that involves using a Raspberry Pi to control all the switchboards in my house. I will start by wiring three switchboards first.
I am planning to use one 8-channel and one 2-channel relay for each of the switchboards, as each of these switchboards contain 10 switches. So, that amounts to 30 relay units.
However, I do not have as many as 30 free GPIO pins on my Raspberry Pi. I can use a port expander, but the Pi is installed with a camera and stationed near a door and fixed there. So, all the 30 wires from the switchboards need to be brought to the Pi, which will make the walls look messy. I was wondering if I could install an Arduino mini for each of the switchboards and control the relays using the Arduinos.
The Arduinos in that case need to the connected to the Raspberry Pi somehow such that when I want to switch on a specific light in my bedroom, I send a command to the Pi. The Pi sends the corresponding information to the Arduino in some well-defined format, like JSON, mentioning the switch number and the action to be performed. The Arduino switches on or off the switch and returns a message to the Pi.
Can this be done? I would be grateful if anyone could help me with this.
Thanks in advance.

Gammu on my Raspberry Pi (2 and 3) works perfectly only for 30 minutes

I meanwhile installed gammu in two different raspberry pi (2 and 3), and it works fine - but only for rather exactly 30 minutes. The daemon (according to top) continues, but no sms is sent or received. A shutdown -r command or a reboot allows to exchange sms - but again only for 30 minutes. I am using a Huawei USB dongle. The whole thing works fine when I ask the Raspi by a cron-job to restart every 30 minutes, but I'm losing then all data of my Python program...
I did a search for many days in Internet. There was the same question asked by someone else in forum-rapsberry.de. Unfortunately unanswered. I kindly ask for help here.
I finally fixed this problem.
Have had this issue as well. But then I worked on some software for the rasp using another serial port for communications with some atmel chips and I figured out that the problem on the rasp is the speed you setup for the serial communication. Sometimes it works and then it just doesn‘t. :p
Well the rasp is cheap and tiny and bits become more unstable the faster your serial data is sent. So simply reduce the speed on the serial port to something lower such as 14400!
The default value („connection=at“) is so so so much to fast (115200 bits per second).
Edit gammu-smsd in /etc and replace „connection = at“ with „connection = at14400“.
/etc/gammu-smsd
# Configuration file for Gammu SMS Daemon
# Gammu library configuration, see gammurc(5)
[gammu]
device = /dev/ttyUSB1
name = Phone on USB serial port USB_Modem USB_Modem
connection = at14400
(…)
Enjoy.
PS: Also ensure your power supply is sufficient: Link

Categories

Resources