Picoballoon - DEVLOG 4# 🎈
Hello guys!
I had litlle break last week, but im back at it. 
I’ve finally started to write my final micropython code for the balloon tracker. (hopefully) :D
I will copy and paste the code here. That way you can look trough it/correct me if needed. :)
(I’ve made a labels for each section)
So far code looks like this: 
#Some importing stuff
from machine import Pin, SPI, ADC, deepsleep
import time
import ucryptolib
#channels settings (frequency / spreading factor)
#There are 2 groups of channels.
#1. MIN_CHANNELS - Most important ones. One channel from each region. (in case of power saving mode)
#2. ALL_CHANNELS - All other channels for higher chance of being detected. (when power isn’t a problem:D)
#US spreading factor is set at 10, because of duty cycle limits.
MIN_CHANNELS = [
(868_100000, 12), #EU868 - 1.
(903_900000, 10), #US915 - 2.
(916_800000, 12), #AU915 - 3.
(923_200000, 12), #AS923 - 4.
]
ALL_CHANNELS = [
(868_100000, 12), #EU868 - 1.
(868_300000, 12), #EU868 - 2.
(868_500000, 12), #EU686 - 3.
(903_900000, 10), #US915 - 4.
(904_900000, 10), #US915 - 5.
(916_800000, 12), #AU915 - 6.
(917_600000, 12), #AU915 - 7.
(923_200000, 12), #AS923 - 8.
(923_600000, 12), #AS923 - 9.
]
#Delay between packets transmitions - radio stabilization
INTER_PACKETS_MS = 300 # 0.3s
#Transmition power set by voltage
POWER_HIGH = 16 #dBm 1.
POWER_MID = 14 #dBm 2.
POWER_LOW = 12 #dBm 3.
#VSYS Power levels
VSYS_HIGH = 4.0 #V
VSYS_MID = 3.3 #V
VSYS_LOW = 2.3 #V
#Time between transmitions based on the voltage level
SLEEP_5MINUTES = 5 * 60 * 1000
SLEEP_10MINUTES = 10 * 60 * 1000
SLEEP_15MINUTES = 15 * 60 * 1000
SLEEP_20MINUTES = 20 * 60 * 1000
#LoRaWAN ABP information from TTN console (fill in YOURS - I will replace them with 1) :-)
DEVADDR = bytes([0x11, 0x11, 0x11, 0x11])
APPSKEY = bytes([0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11])
NWKSKEY = bytes([0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11])
#MESSAGE number
FPORT = 1
#communitacion channel between Pico and RFM95W (SPI0) - it needs 3 signal channels (sck,mosi,miso)
spi = SPI(0, baudrate=1000_000, polarity=0, phase=0, sck=Pin(22), mosi=Pin(19), miso=Pin(16))
#Chip select pin (NSS/SS), reset pin, led pin)
cs = Pin(4, Pin.OUT)
cs.value(1)
rst = Pin(15, Pin.OUT)
led = Pin(25, Pin.OUT)
#RFM95W startup reset
rst.value(0)
time.sleep_ms (10)
rst.value (1)
time.sleep_ms(10)
#voltage measuring pin
adc_vsys = ADC(3)
#4 main tools for communication with RFM95W and voltage mesauring
#1. - write into RFM95W register
def write(addr,val):
cs.value(0)
spi.write(bytes([addr | 0x80, val]))
cs.value(1)
#2. - read from RFM95W register
def read(addr):
cs.value(0)
spi.write(bytes[addr & 0x7F]))
val = spi.read(1)
cs.value(0)
return value[0]
#3. - good nigt for the RFM95W (power save)
def RFM95W_sleep():
write(0x01, 0x00)
#4. - Measures capacitor voltage (calculates avarage voltage from 8 measurings - adds up all 8 of them, then divide them by 8 )
def read_vsys():
total = sum(adc_vsys.read_u16() for _ in range (8)) /8
#now convert raw 16bit number to voltage
return total * 3.3 * 3 / 65535
**Hope it will be readable somehow:D **
AI helped me only with minor things ( converting raw 16bit number, RFM95W registers)


- The radio was left on the default private-network sync word (0x12) instead of TTN’s public sync word (0x34). So the gateway never had a chance to decode it.





) I had to desolder it and i need to replace it.