LoRa communication between RPI and PICO with Waveshare hats - python

I'm trying to make a Raspberry PICO with the Waveshare SX1262 LoRa hat to send LoRa messages to a Raspberry Pi also using a Waveshare sx1262 LoRa Hat.
The radio configuration is different in both devices and I'm unable to see any message sent by the PICO in the RPI.
Communication between 2 PICOs work, and also between 2 RPI using LoRa protocol, but not between different devices.
Initialisation options are very different and I'm wondering which options I should use...
Raspberry PICO configuration (using https://github.com/ehong-tl/micropySX126X code)
sx.begin(freq=923, bw=500.0, sf=12, cr=8, syncWord=0x12,
power=-5, currentLimit=60.0, preambleLength=8,
implicit=False, implicitLen=0xFF,
crcOn=True, txIq=False, rxIq=False,
tcxoVoltage=1.7, useRegulatorLDO=False, blocking=True)
Raspberry Pi configuration (using https://www.waveshare.net/w/upload/6/68/SX126X_LoRa_HAT_Code.zip code)
node = sx126x.sx126x(serial_num = "/dev/ttyS0",freq=923,addr=101,power=22,rssi=True)
AIR_SPEED = 2400
PACKAGE_SIZE = 240 Bytes
Even though the chip is the same, the way to configure them is very different.
Any idea on how to make the 2 devices communicate?
Thanks in advance!

That's because the RPi firmware is weird and the Ebyte E22 chip is even weirder. These managed chips they've been churning out are not sending LoRa packets, and are incompatible with regular LoRa modules.
Look at the initialization code:
node = sx126x.sx126x(serial_num = "/dev/ttyS0", freq=868, addr=0, power=22, rssi=True, air_speed=2400, relay=False)
The air_speed=2400 parameter is definitely not a LoRa parameter (and on the other hand LoRa SF and BW parameters are absent), because the chip is in FSK/OOK mode, instead of LoRa mode. It's the RegBitrateMsb/RegBitrateLsb registers, 0x02/0x03. So the RPi hat can definitely not communicate with a normal LoRa module, unless you bypass the UART management, and rewire it for SPI.

Related

Interact with puredata from gpio on a raspberry pi using python and OSC

Wanted to control puredata patches from a rotary encoder and display informations from puredata on an OLED screen pluged into GPIO in/out of a Raspberry Pi.
I tried to use wiring pi external, but it wasnn't compiling.
I thinked about other methods and came out with this : receive gpio info using python scripts and sending OSC messages to puredata...
I'm not an expert in python nor pd, just something I had to do quickly for a project and wanted to share with you. Any comment or question is welcome.
https://github.com/Matfayt/autonomusberry.git

Using serial ports over bluetooth with micro bit

I have correctly got a microbit working with serial communication via COM port USB.
My aim is to use COM over bluetooth to do the same.
Steps I have taken:
(on windows 10) bluetooth settings -> more bluetooth settings -> COM ports -> add -> incoming
in device manager changed the baud rate to match that of the microbit (115,200)
paired and connected to the microbit
tried to write to both the serial and uart bluetooth connection from the microbit to the PC (using a flashed python script)
using Tera Term, setup -> serial port... -> COM(number - in my case 4), with all necessary values (including 115,200 baud rate)
After doing all of these, I see no incoming message on Tera Term. Have I missed anything?
This is not directly possible via BLE UART communication because it uses different protocols (as mentioned above by ukBaz).
You are able to, however, communicate via custom BLE libraries such as bleak.
Bleak has some good examples on its github repo of how to scan GATT characteristics and services to find the TX and RX characteristics of your BLE device.
From there you're able to connect to the microbit directly over bluetooth and read and write to it's GATT table and not using the proprietary BLE protocols etc.
I'll make a tutorial at some point and link it back here when it's done.

python communication MODBUS TCP/IP raspberry pi and HMI - write value

I'm French student and i need your help in Python for my program.
I've got a program in my rapsberry in Python which acquire datas from temperature and hygrometry sensors.
I need to communicate these values to an Human Machine Interface supervisor by the MODBUS TCP/IP PROTOCOL to display and made some graphics of these values in my HMI
The IP adress of the raspberry : 172.16.0.2
The IP adress of the HMI : 172.16.0.10
I think I need to use package like pyModbusTCP or things like that but I don't understand how to use it.
Could you help me to understand how I made the communication between my Rpi and my HMI and for example how I could write the integer value 100 at the address index 1?
Thanks for all!
Antoine
MODBUS is a single-master protocol, meaning that there can only be one master, the rest of attached devices are slaves ( http://www.ni.com/white-paper/52134/en/ , similar to USB protocol, called host and device there ). In addition in MODBUS protocol a slave never starts a communications, slaves only answer to requests. Consequentially the machine on that your HMI runs has to be the MODBUS master /client ( this naming convention is a bit senseless )
For a quick general overview read this https://www.reddit.com/r/PLC/comments/7bqppu/using_raspberry_pi_as_modbus_slave_and/ and http://www.simplymodbus.ca/TCP.htm
pymodbus client / master on HMI machine
From this master / client you can send requests to the RPi ( MODBUS slave / server ) with its sensors using the following code ( if one of the sensors stores its data in a register that is presented to the bus as coil 1 by the pymodbus server that runs on the RPi, see below ). This is only an example there are other data blocks in MODBUS, namely Coils, Discrete Inputs, Input Registers, Holding Registers which of them you use depends on how you configure the MODBUS server on the RPi, normally Discrete Inputs and Input Registers are rarely used :
client = ModbusTcpClient('172.16.0.2')
client.write_coil(1, True)
result = client.read_coils(1,1)
print(result.bits[0])
client.close()
https://github.com/riptideio/pymodbus
pymodbus server / slave on Rpi
For this to work on the RPi has to run software ( pymodbus server ) that enables it as MODBUS slave / server and the sensors have to write their values into specific memory locations that are presented to MODBUS as coils / registers. How this can be done is in https://www.youtube.com/watch?v=p3Dgd0PDjnU and https://jacekhryniewicz.wixsite.com/website/raspberry-pi-with-modbus-tcp ( is a bit outdated )
In https://github.com/riptideio/pymodbus/blob/master/examples/common/asynchronous_server.py is a working example of a MODBUS server that has to run onthe RPi ( read the comments, especially the lines following # initialize your data store )
The word coils has its origin in the past of MODBUS protocol which was developed when electromechanical relays with coils were used in automation technology

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.

Toggle pins of ethernet port to high / low state?

I am trying to set the ethernet port pins directly to send High / Low signals to light up four LEDs. Is there any way I can simply connect LEDs to the ethernet cable?
What would be the best approach, if using ethernet is not a good option, to light up four LED lights and switch them on/off using a PC.
I am planning to create a command-line tool in Python. So far I have gone through a lot of articles about PySerial, LibUSB etc. and have been suggested to use USB to UART converter modules, or USB to RS-232 converters.
Actually I don't want any interfaces except the PC port and the LEDs as far as possible.
Please suggest!
No, it is not possible. There is no sane way to affect the PHY in PC software.

Categories

Resources