Script hangs up arduino

the next step will be to get the windspeed from these 2 raw values from that file:

i will probably add it this feature in the python script... guess something like that:

    # Use lookup table to correct raw wind speed errors
    def calc_wind_speed_ec(self, raw_mph, raw_angle):

        # some sanitization: no corrections needed under 3 and no values exist above 150 mph
        if raw_mph < 3 or raw_mph > 150:
            return raw_mph

        return self.windcal_tab[(raw_mph - 1) * 256 + raw_angle]

i have

const byte windSensorPin = 2;     // The pin location of the anemometer sensor

but forgot to change everywhere (use the lower cap first letter). corrected now in the code above

This takes care of that and is considered a better way:

const byte windSensorPin = 2;
1 Like

but I had the capitalisation wrong... forgot to change it in the code. fixed now

it would be good also to change all the other variable names so that they are meaningful and start with a small cap.

so your arduino spits data through Serial into that python script?

a look-up table will be faster on your PC for sure :slight_smile:

#!/usr/bin/python

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 = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
org = "paul.matteschk@ea-energie.de"
url = "https://us-central1-1.gcp.cloud2.influxdata.com"

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

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


if True:
	read_ser = ser.readline().decode('utf-8').rstrip().split(",")	
	print(read_ser)
			
	rotx=read_ser[0]
	vvx=read_ser[1]
	wdirx=read_ser[2]
	mbarx=read_ser[3]
	humx=read_ser[4]
	tempx=read_ser[5]
	rainx=read_ser[6]
	
	rot = int(rotx)
	vv = int(vvx)
	wdir = int(wdirx)
	mbar = float(mbarx)
	hum = float(humx)
	temp = float(tempx)
	rain = int(rainx)
            

	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)])

yes thats the python script running simultanously on the Pi4

So I have to load the look-up-table, input rot and vv to get the windspeed..

if you open the Serial port at 115200 bauds, your arduino should also be set at that speed or you won't get the data


that does not do anything useful. it just ensures that whatever was written to ser is sent... Since you did not write anything yet, it does nothing...


don't you want to read in a loop? a while would be better than a if


in my experience it's better to use a dedicated task to read the lines and store the lines in a queue to the arduino and another task that will unpile the lines from the queue and do the database stuff

if not you'll run into concurrency issues and risk loosing data on the serial port

yes i changed the baudrate according to your suggestions. :slight_smile:
The script is triggered with crontab
ok i will delete ser.flush()
never used queue, is it really that much better jackson?

if you wanted to ensure there was nothing in the input buffer, you can use reset_input_buffer()


here you spit data out every 3s

if the database query does not last for more than 3s then you won't have an issue.

if it lasts longer or you accumulate delays after a while you'll start loosing incoming characters. It's not as bad as on the Arduino where the buffer is only 64 bytes deep, you probably will have 1kB or so but nevertheless if you keep this running for a looong time, it might be an issue.

start without it and if you notice you are getting garbage then you'll know where it comes from :slight_smile:

1 Like

hey Jackson, by the way where are you from?

Iam thinking about a python function to notfiy my mobilephone if data communication stopps /fails

or maybe grafana is offering that service ! =)

Citizen of the (Free) world :slight_smile: and traveling around

japan and south korea ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.