Real time plotting of serial data between python and arduino - python

For the mapping of the obstacles in a region, I was planning on using Sharp IR range finders connected with an Arduino Mega and then trying to plot it in real time on a polar histogram type map using python and matplotlib. I was a bit confused about how to proceed through the interfacing of the Arduino and python over the serial connection.
Any help would be great.
Thanks

This might be a good start: Arduino and Python. Summary: use pySerial and read from/write to /dev/tty.usbserial.
See also:
How to send a value from Arduino to Python and then use that value
Receive multiple values via pyserial and display in Python GUI

If you are ok with skipping Python you can do the same thing in Processing. If you just manage to send the data wirelessly over for examble xbee or bluetooth then it would be a piece of cake to connect it to a plotting software like this http://sebastiannilsson.com/en/k/projekt/realtime-plotter/

Related

How to parse specific data from a serial input on a Raspberry Pi?

I am using a GPS module for precise positioning. It's going to be autonomous and we need to make a fail-safe in case the GPS loses its rtk fix.
To do that, I am employing a Raspberry Pi 4b connected via UART to the GPS module. The GPS sends a message, GNGGA, where one of the parameters informs the status of the fix, then the Raspberry Pi monitors these parameters and keeps checking if the fix type stays as rtk fixed and sends an alert if not.
So far I have the code below that connects the Raspberry Pi to the module
#!/usr/bin/env python
import time
import serial
ser=serial.Serial(
port='/dev/serial/serial01'
baudrate=460800
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
counter=0
while 1:
x=ser.readline()
If I print x, I get something like this:
�6ȶ< �>�r�%���a���5��PFpx���� zR�b�qI��#ǃy�v����$p���`X�w�?Ĉ*�����>��G;
A���
O���������r[���nlB>X$GNGGA,202538.90,2156.26451,S,04753.49406,W,1,12,0.52,751.9,M,-6.2,M,,*53
The unreadable part of the code is some other messages the GPS needs, while the readable part is the part I want to extract.
I believe I know the logic behind what needs to be done: I need to recognize the start of this string, and since the size of this is fixed, I should be able to use its length to extract the whole string or just the parameter I need.
I don't have much experience dealing with serial communication with python so I don't know how to employ this logic. After a few hours of trial and error, I managed to find the start of the string with a few if's, but I don't how to go from here.
Can anyone give some advice?

Python - Read a GPS through I2C? How would I do this?

I'm trying to read data from this GPS through python. This GPS is hooked up to my Raspberry Pi 3 B+ via I2C. I need to use I2C communication, as my serial ports are going to be used by a different device.
So far my endless googling has brought me nowhere. I can't seem to find any python libraries that will let me do this. Can anyone here help me get started? Thanks!

How to set up python program that takes input from sensors and analyzes it?

I am collecting data from a DFRobot Gravity Analog Heart Monitor Sensor with a five lead system into a Rapsberry Pi. I am using python to generate the program. How do I create a timer and a data buffer to store this data on an sd card?
your question is quite vague, I don't think the GPIO of the raspberry pi has an analog input. You'll need a Analgo to digital converter such as https://www.adafruit.com/product/1085
This link will actually be quite useful for you as it will introduce Circuitpython from adafruit https://circuitpython.org/ which will help you out in controlling sensors and other circuits with python.

How to read RGB data sent to USB keyboard with Python 3 on Windows?

I have an RGB LED strip hooked to an Arduino Uno and I want to sync that LED strip to the effects currently sent from Razer Synapse to my keyboard/mouse on Windows 10.
Since Razer Synapse only sends RGB data to their hardware and 3rd party hardware (NZXT, Corsair, etc) my other options are to either snoop the RAM for the RGB data that is sent to the devices, or snoop the USB data sent by Synapse to the devices so I don't have to process animations since all will be done by Synapse.
I've tried to use Device Monitoring Studio to read USB data and I did manage to find what I wanted but I am not sure what kind of data that is and how to get the same data into Python programatically.
I've tried to use pywinusb and the raw_data.py example to read raw data from the keyboard itself but I don't get anything. Maybe I'm not using the proper library for my task.
How do I get that (assuming binary) data with Python to send it via serial to my Arduino ?

How to get live plot data from headless Raspberry Pi?

I'm new to using a RaspberryPi. Until now I was experimenting with an Arduino.
If I connect an Arduino by usb it is recognized as COM device and with the Arduino serial plot software it was easily possible to live plot sensor data.
For my next project I want to work with an Raspberry Pi Zero W and Python.
Is it possible to send serial data from a python script over the charging usb-cable like with the Arduino? If not, what would be the easiest way to send sensor data e.g. to matplotlib to plot the data directly?
It is possible. However I would not recommend using the USB serial port profile. While it works, it is severely limited in comparison to the alternative. Which is using one of the various ethernet gadget modes.
One tutorial for setting this up is e.g. http://www.circuitbasics.com/raspberry-pi-zero-ethernet-gadget/
The result of this is a full network interface that you can not only use to transfer data over a TCP/IP socket but at the same time run a SSH-connection to start and monitor your application. Even to develop by using a SSH-enabled editor such as Emacs. So the possibilities are much bigger than over the single-stream serial setup.
If it absolutely has to be serial, that's of course possible too - follow e.g. this tutorial: https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/serial-gadget

Categories

Resources