I'm building a project where I have multiple Arduinos, each having a temperature sensor and a [input wireless transmission method here].
This data would be received by a controller, a Raspberry pi, which would act as the server: call to Arduino, collect the data, and store it. This data would be accessible to a Mobile App, but this is out of the scope of the question.
Requirements:
Arduinos must read simple raw data (in this case, the temperature reading from the sensor) and make it accessible to the Raspberry pi, which would make calls to each Arduino board (from 1 sec to 1 min time frame).
Arduino side must have a low energy consumption, as it would be powered by a small battery;
Data transmission on Arduino end must be as cheap as possible and work in low temperatures (around -5 degrees Celsius). They would be stored be inside a freezer, so temperature and a thick-ish metal layer are obstacles to overcome.
Question: is Bluetooth a viable transmission method? Is it possible to pair multiple Arduinos to one Raspberry pi at a single time?
If Bluetooth isn't any good, what is? Correct me if I'm wrong, but Wifi is a high energy consumption solution.
OBS: if needed, the Raspberry Pi board could be swapped for an Arduino one.
Cheap, low power and tiny row data?
I suggest you to use nRF 2.4GHz transceiver module. It may look some old school way but will meet with your requirements.
It consumes 0.9 nA while deep-sleep mode and ~10mA for just transmission.
Also it is easy to program and due to its connectionless arch, you will not need to know states about the connection. Just being sure to send and received successfully, suggest you to add deviceId and succeed flag in your raw requests.
Here is vendor site :
http://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01
Good luck!
Related
I'm trying to act as a master with my Pi 4 B in an rs485 Modbus communication.
I'll ask for register values.
All ok with pyModbus and a USB-RS485 (like ftdi) using its virtual com (/dev/ttyUSB0)
Now...
I summoned the uart4 with the standard procedure.
dtoverlay=uart4,ctsrts
So I'll be working with /dev/ttyAMA1, TX=GPIO8, RX=GPIO9, RTS=GPIO11, CTS=GPIO10
I bought one of those cheap TTL/RS-485.
DE and RE are connected to uart RTS (CTS enabled but not used).
TX to DI, RX to RO
I ask for 5 registers one at a time (with 3s timeout for the response each) and a final pause of 3 sec.
I connected some LEDs and slowed the baud rate to 1200 to see how LEDs act.
From the other side, I'm monitoring Modbus activity with ftdi USB-rs485 and dock light programmed to respond with a certain message (acts as a 'fake' slave)
No activity of the ftdi at all.
If I de-attach DE and leave only RE with RTS, I see the TTL TX message on the RX pin (like a looping echo).
What's wrong??
I bought one of those cheap TTL/RS-485. DE and RE together and connected to uart RTS (CTS enabled but not used).
That is not right. With Modbus only one device is allowed to use the bus at a time, so you need one of those GPOx (it can also be RTS or CTS) to go low right before the device is ready to write something on the bus and stay low until the whole frame is transmitted. After a determined amount of time elapses, the signal has to go high to free the bus and allow other devices to talk.
For the practical part, since this is a very common problem, you will find all you need to fix your problem in this Q&As. A very short summary: you need to tweak whatever library you use to add the signaling to feed the drive enable/read enable pin on your TTL converter.
If you are wondering why the USB converter works and the TTL won't, the answer is very simple: your USB converter has this signal implemented in its hardware (you can read more details on the link).
The problem is not difficult to fix, but if you are short on patience or don't have time to waste, just take the fast track and buy a decent transceiver. There are many options, this is just one (I'm not affiliated with the manufacturer nor I make any profit off it). You can also stick to those connected through USB; most of them will work (not all though).
If you decide to implement the software solution be aware that you will be asking for real-time performance on a non-real-time platform, meaning that even though the solution will probably work almost 100% of the time, it is not guaranteed to always work. If your RPi is loaded with too much work, there might be instances where the signaling will not be properly timed and some frames might not get to the other side. You are warned: if your application is mission-critical in any way, just forget about it and buy a proper transceiver.
I am looking for a DIY replacement for the $1500 Go-Box for mass provisioning Chromebooks. I have managed to replicate this by using a Raspberry Pi Pico as the "HID Emulation". However, I need this on a mass scale. I want to be able to do 20 Chromebooks at one time. I can do this with just 20 Raspberry Pi Picos but I need to change the script every 100-150 Chromebooks I provision (changing credentials etc.). Changing each script manually is time-consuming, so I need to be able to change all 20 scripts at once, or one "master" script that the "slave" Picos go and get on boot.
At first, I thought about an SD card they can all read from and when needed, I can take it out and change the script on there, and then when the Pico boots it can copy the new script to the root of the Pico. However, this may be an issue since I do not know if the Picos will clash with each other when trying to read the script from the same place at the same time. This is my first issue.
Then I thought about a Master and Slaves setup. One Pico acts as a Master and holds the script. The other 20 are slaves that get the script from the Master when a pin is high (to signify the Picos need reprogramming). I would only use the Master when reprogramming the script. When I turn the Master on, I would have it set a pin to high and all the other slaves would check on the boot to see if the pin is high. If the Slaves find that the pin is high, it won't run the script, but it will update it from the Master. This is where I run into the problem with this method. I need to transfer the script from Master to Slaves. I haven't got any experience in communication protocols like UART, SPI, or I2C but I understand that if I want to do multiple Slaves, then I am better off using I2C.
This is my last resort since I have been googling for days and can't find a suitable solution. Is anyone able to provide any insight on any of the following:
How to get the script from one place to twenty?
Will the SD card idea clash when all 20 Picos try to access it?
How to transfer files over I2C or similar protocol?
I appreciate any help anyone can provide. I am using MicroPython v1.16 on 2021-06-18; Raspberry Pi Pico with RP2040
The pico has a uart (2 actually) which is easy to program; there are lots of examples of serial communication with the pico, typically to a full Raspberry Pi.
You could join all the rx receiver pins on the picos to the master tx transmit pin and talk to them all in parallel, with no replies.
I don't know if it is possible to tri-state the tx pins so that they could all be connected too, but only one enabled at a time, by sending suitable commands from the master tx. The problem is that the electrical load of 20 receivers, and the excessive length of the parallel cabling might not give error free transfers.
Or you could daisy chain the serial ports so the rx of pico1 is read by the software there and repeated out on its tx, which is connected to the rx of pico2, and so on. You can start each data packet with a "node number", which each pico decrements before sending it on. If this number is 1, then the packet appplies to this node. This is a sort of auto-numbering of the picos. A number like 255 can be used for a broadcast.
If the last pico's tx is wired back to the master you can even allow any pico to send a reply, provided the software waits for a break in incoming data.
It also allow for rudimentary flow control and error checking. If the master sends only 1 byte at a time, and waits for each byte to be "echoed" back from the last pico, it can ensure everyone has seen the data. Also, each serial segment can be short so there are no electrical load problems, or signal corruption.
Look at the gpib bus which daisy chains something like this, or at the simple individually-addressible RGB leds like the WS2812B which are also daisy chained.
How can I set HIGH or LOW to a usb port connections using Python.
This could be used in come custom usb device.
For Example,
Consider I have a LED connected to the usb port(DATA Line) .
Now through the code I want to blink it or control it.
Now this can be easily achieved by using any micro controller, Arduino, Raspberry Pi
But I want to achieve this with with a normal computer and python.
[EDIT]
Can I achieve this by making a C or C++ API and make a wrapper to use it in Python. Is yes then what will be the best way to achieve it?
NOTE :
My main objective isn't just blinking some LED. I just gave it as an example.
I want to be able to directly control the USB ports.
Quoting : https://www.cmd-ltd.com/advice-centre/usb-chargers-and-power-modules/usb-and-power-module-product-help/usb-data-transfer-guide/#:~:text=How%20is%20data%20sent%20across,amounts%20known%20as%20'packets'.
Within the standard USB 2.0 connector you can see four metal strips. The outer two strips are the positive and ground of the power supply. The two central strips are dedicated to carrying data.
With the newer USB 3.0 connector, the data transfer speed is increased by the addition of extra data-carrying strips; four extra signalling wires help USB 3.0 achieve its super speed.
I want to set the values of the Data pins.
By my saying HIGH LOW please don't misunderstand that I want to set the value to +5V and GND. But I mean to control its value directly via my code without any external driver present in the computer.
I mentioned HIGH LOW to just make the language simple and so that it is easier to understand.
Controlling components like LEDs from devices like Arduino and Raspberry Pi are done using GPIO pins. In contrast, USB is designed for data transfer and not for maintaining more constant high or low signals like GPIO. It also consumes different voltage and current levels than GPIO pins and could potentially damage components meant for GPIO.
However, you can get USB to GPIO adapters for this purpose (see here for an example discussion on these options).
In terms of Python, you can use packages such as PyUSB or the libusb Python wrapper to control/transfer data/communicate with USB devices (such as the USB to GPIO adapters). The companies providing the adapters might also have designed their own easy-to-use Python package to wrap around a lower-level driver (probably written in C). See this USB controlled LED device as an example with its own Python driver. The drivers are just software programs that take in relatively simple commands from the user for what they want a device to do. They then encapsulate the lower-level complexities required for following a protocol to communicate the user's intention to the USB device and controlling the USB port at the lowest possible software level.
You cannot achieve that for several reasons:
The USB port has its own protocol of connection. Data is transmitted in packets with starting and ending bits. The negotiation and handshake process is done in the hardware layer between microchips. This process also selects the communication speed in the bidirectional data line. You have to direct access to the pin (like GPIO) to turn LEDs ON and Off or create your own connection protocol. This cannot be done in USB.
There are also voltage and current limitations. The data line is not +5 and GND. The data line is 2.8v for D+ and 0.3v for D- and both with respect to the GND. The data is transmitted and received differentially (D+ with respect to D-) and they are not compared with the GND for 1s and 0s.
The button line is you have no direct control over USB.
I'm running a Python script on a Raspberry Pi Zero that records audio, does some processing and TF analysis. Right now the Raspberry is always connected to the power supply, but I want to run while on the move by attaching a battery. However, most of the models of battery and power management boards I have found can't report to the Rasp Pi when the battery is low so you can do a "soft" power down.
What is the risk of the Raspberry Pi Z shutting down suddenly when the battery runs out of juice?
Is there any option that the power management board has a I2C/GPIO comm with the CPU so you can read the battery level?
Four years ago I worked on a project that used a Raspberry (it wasn't the Pi Z, but I think the problem is similar). We also came across into this problem. So, sharing my experiences with you according your topics:
our project was using a battery and sometimes it it runs out of juice. At first it seems ok. But later we got a problem on the SD card that we needed to replace it. So, based on my experience, I don't recommend you to do that
In the project we also had a Arduino communicating with the raspberry. So we just use a tensorflow divisor to mesuare the voltage on Arduino analog in, and send it to raspberry using the USB port. Of course, it is not your case, we just use it because we already had this hardware on the project. For your case, I think a safe option is buy a shield that do that for you. I don't know your budget, but it's a good idea.
My issue is to make a serial communication between raspberry pi and another hardware. The recommended connection for this hardware is as shown on the manual, I have to connect, RX, TX, GND, RS, and CS.
But on raspberry pi we have only RX, TX so I connected RX and TX and The GNG of Pi to this hardware.
I modified Pi's parameters as shown on the link : here
Then I maked a simple python program that initialize the communication, and send data.
Here is the code :
import serial,os
port=serial.Serial("/dev/ttyAMA0",baudrate=9600)
print ('port is ok')
port.write('Command')
rcv=port.read(10)
print rcv
after running this code on pi, I got ('port is ok'), But the problem is that this hardware don't respond correctly to the command, and as respoce it gave me normally OK, but I got some extra caracter( non readable).
Is that a problem of encoding? Can some one help about this?
You need to check the baud rate on the other hardware
or make sure that the length of the received message = to the printed message.
In a serial communication, there are two important things to be careful :
The two devices have to work with the same baudrate IF the link is bidirectional.
When writing data on serial, you have to flush data just after the write().
refer to here for it.
In a lot of case, flush isn't needed, but when two different devices have to communicate, it could unlock the comm'.
If it's not efficient, try to set up your other device with the same conf (no flow control, etc)