Arduino Uno Serial Raspberry Pi4B

Raspberry Pi4B serial to Arduino Uno

Goal: direct upload of data from arduino uno using internet from raspberry pi…Is that possible?

The library in arduino for influxdb uses esp wlan module…

Currently Iam able to readout utf-8.rstrip() from arduino with python script over raspberry. but i guess that format wont be fit in influxdb easily…

Any thoughts?

measuring wind temp press rhum

I had the same setup once before I moved it to ESP.
Just send numbers from UNO, without units (e.g. comma separated), and you will be ok with ASCII chars.
You can use InfluxDB Python client to write data.

import serial
import time
from influxdb import InfluxDBClient
import urllib3

ser=serial.Serial("/dev/ttyUSB0",9600)  #change ACM number as found from ls /dev/tty/ACM*

client = InfluxDBClient(server,8086,user,password, database, True, False)

while True:

  if len(data) == 3:
       "tags": {
       "fields": {
  if len(data) == 1:
       "tags": {
       "fields": {
1 Like

dude sorry for the late response. thanks for your help.

thats my output now

Is your code fore arduino? (.ino?)
how to i get the datfor server, database etc?

The example I’ve provided above is python code running on raspberry using Python client for InfluxDB 1x.
It reads data from the virtual serial driver which is loaded when Arduino is connected via USB cable to Raspberry Pi.
It reads lines and splits each row into values by the comma char. As you are using a semi-colon as a separator char, you need to modify it.
Split data is written to the database via JSON payload used by the python client.

Ahh great got it. My goal is to use the influxdb cloud service.

I created a bucket there. Did you the same?

My code was used at the time when there was only InfluxDB 1, so it is using the client for v1. You can easily use examples as you posted above to adjust code to write data to InfluxDB 2 Cloud. When you parse lines into an array of strings, you can use those parts to fill Point.

I would recommend you to first try the examples without data from Arduino to make sure your code to write data works ok, then add code to read and parse Arduino measurements.

hy vlasta,

the arduino publishes the mesaured values every ~ 3s

how would you recommend to proceed in my script, so that it always asks for data when numbers are publish (match timing)


import serial
import json
import influxdb_client
import os
import time
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

bucket = "AllSkyLA"
token = os.environ.get("INFLUXDB_TOKEN")
org = ""
url = ""

client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)

ser = serial.Serial('/dev/ttyACM0', 4800, timeout=1)

#using crontab
if True:
	read_ser = ser.readline().decode('utf-8').rstrip().split(",")	
	rot = int(rotx)
	vv = int(vvx)
	wdir = int(wdirx)
	mbar = float(mbarx)
	hum = float(humx)
	temp = float(tempx)

	write_api = client.write_api(write_options=SYNCHRONOUS)					
	write_api.write(bucket=bucket, org=org, record=[Point("Arduino").field("rotations", rot).field("vane_value", vv).field("wind_direction", wdir).field("air_pressure", mbar).field("humidity", hum).field("temperature", temp).field("rain", rain)]) 

if I run the following code its random if it hits the values…

ahh i changed the timeout in

ser = serial.Serial('/dev/ttyACM0', 4800, timeout=1)


ser = serial.Serial('/dev/ttyACM0', 4800, timeout=5)

now it gets the data successfully

1 Like