Hari Hendaryanto

I work at pt. citra sari makmur, vsat and internet service provider since 1997. I started to seriously write this blog since 7 years ago. mostly on technical issues.

Nov 272022
 

Straight to the codes.
We’re going to get PMS7003 values and print them to serial monitor.

compile and download these codes to arduino nano

#include ""PMS.h""
#include <Wire.h>  
PMS pms(Serial);
PMS::DATA data;
void setup()
{
    Serial.begin(9600);
}

void loop()
{
  if (pms.read(data))
  {
    Serial.print("PM 1.0 (ug/m3): ");
    Serial.print(data.PM_AE_UG_1_0); 

    Serial.print(", PM 2.5 (ug/m3): ");
    Serial.print(data.PM_AE_UG_2_5); 

    Serial.print(", PM 10.0 (ug/m3): ");
    Serial.print(data.PM_AE_UG_10_0); 
    Serial.println();           
  }  

open serial monitor on Arduino IDE, set the baudrate to 9600 bps, you’ll see the beautifull data coming from PMS7003.
that’s it, pretty simple wight?

Hey!! i want those values grabbed to my raspi zero for my weather station
easy, i can connect PMS7003 sensor serial pin to my raspi UART. but wait, there’s logic level difference between my arduino nano pin I/O and PMS7003.
so, i think the safest way is using usb connect to raspi usb. in my case when i plugged nano to raspi, it will immediately recognized by raspi.

 
pi@raspberrypi:~ $ lsusb 
Bus 001 Device 006: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Bus 001 Device 004: ID 1546:01a7 U-Blox AG [u-blox 7]
Bus 001 Device 003: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller
Bus 001 Device 002: ID 2109:2813 VIA Labs, Inc. VL813 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

take a look at

[Bus 001 Device 006: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC]

in my case nano will be on ttyUSB0

pi@raspberrypi:~ $ grep -i 'tty' /var/log/syslog*
/var/log/syslog.1:Nov 20 19:17:23 raspberrypi kernel: [434783.042818] usb 1-1.4: FTDI USB Serial Device converter now attached to ttyUSB0
/var/log/syslog.1:Nov 20 19:18:42 raspberrypi kernel: [434861.956242] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
/var/log/syslog.1:Nov 20 19:19:13 raspberrypi kernel: [434892.390729] usb 1-1.4: FTDI USB Serial Device converter now attached to ttyUSB0

pi@raspberrypi:~ $ ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 0 Nov 20 19:22 /dev/ttyUSB0

let’s get on the python script

#!/usr/bin/env python3
import serial
import time
import sys

#Serial takes two parameters: serial device and baudrate
nano = serial.Serial('/dev/ttyUSB0', 9600)
nano.flushInput()

while True:
    data = nano.readline()
    strs = data.decode().strip())
        print(strs)
    time.sleep(1)

run it, python tne_code_abobe.py

PM 1.0 (ug/m3): 27, PM 2.5 (ug/m3): 40, PM 10.0 (ug/m3): 49
PM 1.0 (ug/m3): 27, PM 2.5 (ug/m3): 40, PM 10.0 (ug/m3): 50
PM 1.0 (ug/m3): 27, PM 2.5 (ug/m3): 40, PM 10.0 (ug/m3): 50
PM 1.0 (ug/m3): 27, PM 2.5 (ug/m3): 39, PM 10.0 (ug/m3): 50
PM 1.0 (ug/m3): 27, PM 2.5 (ug/m3): 39, PM 10.0 (ug/m3): 50

that’s it 🙂

Nov 172022
 

You can built your own weather station using Argent ADS-WS1 or any other devices that capable submiting to aprs-is or cwop network, but it was too expensive for me.
i began my research how to craft APRS WX packet using python and bash script on direwolf. that
was not easy for newbie amateur like me, LOL. Luckily i’ve found aprs-weather-submit created by KC1HBK.
it makes my research easier.

first of all, we need some hardwares Raspi Zero, BME280 sensorand some jumper wires.
Conect all wires from pi zero to bme280 using i2c pin. you can find pinout configuration here:

https://pinout.xyz

or type pinout in ssh shell

don’t forget to activate i2c pin, go ssh shell. issue command sudo raspi-config and go to interface options to activate i2c

Wiring:

  1. BME280 VIN pin connects to GPIO pin 1 (3.3V)
  2. BME280 GND pin connects to GPIO pin 6 (GND)
  3. BME280 SCL pin connects to GPIO pin 5 (SCL)
  4. BME280 SDA pin connects to GPIO pin 3 (SDA)

i’m using python and bme280 library from https://github.com/pimoroni/bme280-python
there’s some example script there, i silghtly modify the script to obtain bme280 values

building aprs-weather-submit.

git clone https://github.com/rhymeswithmogul/aprs-weather-submit.git

cd aprs-weather-submit

follow the instructions at build scripts section here:

https://github.com/rhymeswithmogul/aprs-weather-submit/blob/master/INSTALL.md

./autogen.sh ./configure [--disable-aprs-is] [--enable-debug] 
make 
sudo make install

when i first compiled, i got this error:

modify main.c

vi src/main.c

at line 588

i changed this line from:

(note at %lu)

fprintf(stderr, “Your comment was %lu characters long, but APRS allows %u characters. Your comment was truncated.\n”, strlen(optarg), MAX_COMMENT_LENGTH);

i changed it to %ul

than it compiled propperly.

here is my wx.sh script to generate wx format:

wx.sh

#!/bin/bash
STR=$(/home/pi/bme280_cjb_AA.py)

Temp=$(echo $STR | cut -f 1 -d" ")
Hum=$(echo $STR | cut -f 3 -d" ")
Bar=$(echo $STR | cut -f 2 -d" ")
Alt=$(echo $STR | cut -f 4 -d" ")
#aprs-weather-submit -k YD0BCX-13 -n -06.714692S -e 106.728514 -t $Temp -A $Alt -h $Hum -b $Bar -V 9
STR2=$(aprs-weather-submit -k YD0BCX-13 -n -6.198611 -e 106.87000E -T $Temp -h $Hum -b $Bar -M " WX on Pi Zero + BME280 + DW 1.7")

echo "${STR2:22}"
#echo "$Temp $Hum $Bar $Alt"

/home/pi/bme280_cjb_AA.py

chmod 755 bme280_cjb_AA.py

#!/usr/bin/env python
#Import modules for time and to access sensor
import time
from smbus import SMBus
from bme280 import BME280
#Initialise the BME280
bus = SMBus(1)
bme280 = BME280(i2c_dev=bus)
#Get data and discard to avoid garbage first reading
temperature = bme280.get_temperature()
pressure = bme280.get_pressure()
humidity = bme280.get_humidity()
altitude = bme280.get_altitude()
time.sleep(1)
#while True:
temperature = bme280.get_temperature()
pressure = bme280.get_pressure()
humidity = bme280.get_humidity()
altitude = bme280.get_altitude()
if ( temperature and pressure and humidity and altitude ):
print('{:05.2f} {:05.2f} {:05.2f}'.format(temperature, pressure, humidity), round(altitude),  end="")
time.sleep(1)

in wx.sh, there’s command part
echo “${STR2:22}”

this command will remove leading 22 characters(based on my lat long value)
in this case when i’m executing aprs-weather-submit -k YD0BCX-13 -n -6.198611 -e 106.87000E
the result will be:
YD0BCX-13>APRS,TCPIP:@200431z0611.92S/10652.20E_…/…t…aprs-weather-submit/1.6

we need to remove “YD0BCX-13>APRS,TCPIP:” part, that’s what “echo “${STR2:22}”” is for.

if it’s not removed direwolf will also submit those part and make it position beacon failed to aprs-is(YD0BCX-13>APRS,TCPIP*: submit 2 times)

direwolf configuration:

ADEVICE plughw:1,0
#ACHANNELS 1
#CHANNEL 0
MYCALL YOURCALLSIGN
MODEM 1200
IGSERVER rotate.aprs2.net
IGLOGIN YOURCALLSIGN passcode

CBEACON sendto=IG delay=1 every=05:00 infocmd="echo '>WX Station' $(date)"

CBEACON sendto=IG delay=01:10 every=10:00 infocmd="telem-parm.pl YD0BCX-13 Temperature Pressure Humidity Altitude"
CBEACON sendto=IG delay=01:11 every=10:00 infocmd="telem-unit.pl YD0BCX-13 deg.C hPa % masl"
CBEACON sendto=IG delay=01:11 every=10:00 infocmd="telem-eqns.pl YD0BCX-13 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0"
CBEACON sendto=IG delay=01:15 every=10:00 infocmd="telem-data.pl telem-seq.sh /home/pi/bme280_cjb_AA.py"

CBEACON sendto=IG delay=1 every=05:00 infocmd="/home/pi/wx.sh"

IBEACON sendto=IG delay=30 every=30 via=WIDE1-1

LOGDIR /var/log/direwolf
PTT GPIO 21

note on direwolf configuration, i also submiting telemetries data, you can ommit it if you want.
i think that’s it. i’m not good at talking or writing.

if there’s something to ask just drop me a message 😀