Oct 24 2022
Raspberry Pi PICO W
from PICO

yes, today 24.10.2022 / late, the
PICO W pdf doc rp2040 ds
is nothing new... but
after play PICO (about 1 / 2021 ) the PICO W has a added WIFI chip and with that similar functionality as a ESP32
-a- on my preferred shopping channel SHOPEE not find PICO W ( or heavy over priced )
today i found out that the official source / for this region / Cytron MY /
+ + has stock &
+ + allows now normal bank transfer
+ + and even CashOnDelivery
-b- read that now for PICO W there is a beta version of Circuit Python ( driving new WIFI chip )
>> so now i ordered it
( for 280 THB / 7.5 Euro from CYTRON by DHL with Cash On Delivery )
( where the old PICO would be 180 THB )
and CNX already (wait all day for DHL delivery 27.10.2022, ok 28 morning ):
i want go the FULL WAY again,
means try
RPI
* 1 * : Raspberry Pi Pico C/C++ SDK
* 2 * : via Arduino IDE
* 3 * : Micro Python
* 4 * : Circuit Python
ADD would like to try DEBUG PICO W ( like with PICO... )
info
follow
on a win 10 PC i download
-1- official IDE
DO NOT FOLLOW THIS! it did not work
VSCodeUserSetup-x64-1.72.2.exe
vs_BuildTools.exe
cmake-3.25.0-rc2-windows-x86_64.msi
arm-gnu-toolchain-12.2.mpacbti-bet1-mingw-w64-i686-arm-none-eabi.exe
python-3.11.0-amd64.exe
Git-2.38.1-64-bit.exe
i follow: youtube
but at end build not work ? version conflict?
ARM


CMAKE



VSCODE



VScode TOOLS


PYTHON



GIT




'open 'win 10' cmd window
cd ..
cd ..
' I am on C:
mkdir Pico
cd Pico
git clone -b master https://github.com/raspberrypi/pico-sdk.git
cd pico-sdk
git submodule update --init
cd ..
git clone -b master https://github.com/raspberrypi/pico-examples.git
'close cmd window

'open developer commend window (2022 v17.3.6 )
cd C:\Pico
setx PICO_SDK_PATH "..\..\pico-sdk"
'close developer commend window
'open developer commend window (2022 v17.3.6 )
cd C:\Pico
setx PICO_SDK_PATH "..\..\pico-sdk"
'close open developer commend window
cd pico-examples
mkdir build
cd build
cmake -G "NMake Makefiles" ..
nmake : ERROR


also here is a better style for the workflow
what shows that the versions are critical??
try other way:
if you use the ( similar to Raspbberry Pi ) setup tool: github.com/ndabas














ok, better, 3 uf2 files there, so the build worked, i compared with /build/ under raspberry pi linux same.
with the first test of VScode (2019) it failed...
later will try dig deeper.
( well for me that PICO SDK thing under Windows is just a mess / unusable for beginner ! like me )
side step: use a Raspberry Pi 4B
( with original 32bit RPI OS )
https://downloads.raspberrypi.org/raspios_armhf/images/raspios_armhf-2022-09-26/2022-09-22-raspios-bullseye-armhf.img.xz
burn to 8GB USB3 datatraveler 111
using raspberry pi imager v1.7.3 with presetup
( name , ssh , password, wifi ,wifi-country, timezone, keyboard )

(after the installation of PICO tools and VSCODE of the 8GB only 470MB free / lucky )
+ boot in RPI4 ( with ethernet cable / hdmi cable / power cable / optional: keyboard / mouse )
+ use mobile FING to find RPI IP
+ use win PC Bitvise SSH Client to login
+ + setup VNC and fixIP update ... and install my defaults
and use the pico_setup.sh
chmod +x pico_setup.sh
./pico_setup.sh


good, already find examples for PICO W, like

still on RPI4 with installed PICO SDK
now try to get the basic running:
first need to check ( depending where you installed the SDK )
where is:
/home/pi/?/pico/pico-sdk/pico_sdk_init.cmake
here mine is ? == "projects/PICO"
CMakeLists.txt need that info for include!!!
under that i make a new project
mkdir hello_usb
cd hello_usb
nano hello_usb.c
nano CMakeLists.txt
mkdir build
cd build
cmake ..
make
-1- the code is a combination of BLINK and print to USB examples
both are tricky!!!
* as with PICO the print goes default to a UART pin and not back to USB
* as with PICO W the LED is not on GPIO, its on a pin of the WIFI chip
-2- the CMakeLists.txt you can not find from the examples so easy,
as they are nested over sub-directories and need to be combined from the 2 examples too,
plus i needed the board settings, actually i not understand where that is done for the examples?

and, after above all worked you get a
/hello_usb/build/hello_usb.uf2
file you can copy to the board after a power-up [bootsel] button pressed and find a usb drive at /media/pi/RPI-RP2/
with copy *.UF2 the drive vanishes ( got some warnings too )
and the board starts blinking.

now how about the printing to USB?
i made a .bash_aliases with
alias PICO='minicom -b 115200 -o -D /dev/ttyACM0'
so with PICO i get a minicom window what prints the
"Hello, world! i am PICO W and can BLINK too" lines

end minicom with [ctrl][a][x]
now i delete the /build/.. dir and want VSCODE to do it again:
in the dir with the *.c file type
code .
first time have to adjust the compiler to GCC for arm non-eabi [change active kit]
and then build [Build]
( buttons down in the last line )

so i run on a RPI4B / 4GB Ram /
after start code the cpu is on limit but just wait it out.
the tools works even faster as in the above manual way,
but the code editor is not usable.. ( ok i am on VNC what has also a lag )
but when i edit a file and use the key arrow up / down i not want to see that 2 sec later.
fixed https://code.visualstudio.com/docs/setup/raspberry-pi
https://ratticon.com/how-to-fix-slow-visual-studio-code-on-raspberry-pi-4/
//__ end side step Raspberry Pi and back to win 10 __//
-2- arduino IDE
arduino-1.8.19-windows.exe
i did installed a nightly update, so its called 1.8.20
using the preferences ( can add with , )
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

select the board PICO W

find the example for the AdvancedWebServer ( save as own project / build / select port USB cable )

after RESET FLASH ( by copy flash_nuke.uf2 into [bootsel] powered board
the arduino IDE only finds a port: UF2 connection....
but a upload to that worked!
later i reconnect USB and it was back on COM20.

now there is no info ( serial monitor not show anything) , but i found its STA webserver IP 192.168.1.10 and call it from browser

now that looks much like the examples for the ESP web server
-3- micro python
thonny-4.0.1.exe
rp2-pico-w-20221027-unstable-v1.19.1-594-g65fa7fd8b.uf2
rp2-pico-20221027-unstable-v1.19.1-594-g65fa7fd8b.uf2
-3.1- setup
install THONNY
!! as i used circuit python first: power board with usb cable while press [bootsel]
RESET FLASH
copy over flash_nuke.uf2

install MICRO PYTHON
copy over rp2-pico-w-_____.uf2


start THONNY IDE
select micropython RPI PICO on COMxx
edit main.py and save to RP2040
help
-3.2- 3 AIN code test

-3.3- webserver
follow tomshardware

index.html
main.py
-3.4- MQTT
micropython MQTT to RPI4 broker
well, i just did play about ESP8266 / sonoff s31 / to RPI MQTT broker / with NodeRed dashboard
so that sounds very interesting.
coming soon
-4- for circuit python:
MuEditor-win64-1.1.1.msi ( and install )
* Circuit Python 800beta ++
adafruit-circuitpython-raspberry_pi_pico_w-en_US-20221027-2bba6a6.uf2
adafruit-circuitpython-raspberry_pi_pico-en_US-20221027-2bba6a6.uf2
* lib and examples
adafruit-circuitpython-bundle-8.x-mpy-20221027.zip
* for cleanup PICO boards flash
flash_nuke.uf2
-4.1- circuit python setup
start: unpack PICO W
( later solder headers / see at the end )
connect PC USB and see drive! ( if not first time need to press [bootsel] while connecting )

copy Circuit Python to drive ( board auto reboot )

start MU editor / connect
LOAD ( from board ) / run code.py

-4.2- circuit python example project
make a 3 Ain to adafruit IO test
info from here

code without the libs and .env file
while play with a jumper cable : 36 3v3 out OR 33 AGND to 31 A0, 32 A1, 34 A2
-4.3- circuit python example webserver
thanks to
using this library: https://t.co/an8nn5IAOF
— Blitz City DIY (@BlitzCityDIY) October 29, 2022
follow httpserver/en/latest/examples

code.py
index.html
-4.4- circuit python example webserver + AIN datapage

code.py
index.html
here i have trouble with the adafruit_httpserver :
return HTTPResponse(body=XXX
( serves a empty static html page with the dynamic XXX inside a < pre>XXX pre> )
i can not send a dynamic html page string ???
return HTTPResponse(filename=
( serves a static html page )

need to test
looks good now:

code.py
-4.5- circuit python MQTT
while we have already used adafruit IO i want know if that
circuit python mini MQTT lib can be used to connect to a RPI4 MQTT Broker
connecting-to-a-mqtt-broker
mqtt api
ok, try to modify my 3Ain adafruitIO example / with the help of Lady Ada's code
to a 3Ain MQTT Raspberry Pi Mosquito Broker
so here back to the RPI4-32 and install
sudo apt update sudo apt upgrade
sudo apt install mosquitto mosquitto-clients
sudo systemctl status mosquitto
sudo nano /etc/mosquitto/mosquitto.conf add
allow_anonymous false
password_file /etc/mosquitto/pwfile
listener 1883
now set user and passworde for the PICO W board circuitpython MQTT client
sudo mosquitto_passwd -c /etc/mosquitto/pwfile u213
password p213
repeat p213
also can test it with a python simulator
pip3 install paho-mqtt
mqtt_client.py
to see that from a other terminal window:
mosquitto_sub -h localhost -u "u213" -P "p213" -t "P213/#"
also use python to cache that stream and save to a CSV file
mqtt_sub_power_meter.py
back on the win PC
and restart the PICO W board
on RPI4-32 test subscrib

code.py
.env
until now i used the 3 analog in from pico w ( online read have quality problems?? but still better as ESP analog in )
but have idea to use my ADS1115 adafruit 16bit ADC / I2C connected / 4 channel / 800s/sec / as a 2 differential input
(like for volt and current measurement of a DC power supply )
find in bundle lib dir adafruit_ads1x15 and copy into pico w /lib/
find also examles adafruit-circuitpython-bundle-8.x-mpy-20221031\examples\ads1x15_ads1115_simpletest.py and other
make a switch to use normal analogs or busio analog break out ( ADS1115 on x48 )


on RPI4 broker use
'mosquitto_sub -h localhost -u "u213" -P "p213" -t "P213/#"
measuring delta over 1 or 2 batteries

cope.py
here i need to check more on the
ads.gain
feature for use together with 2 differential channels
as i want use
chan01 Volt from a voltage divider 48VDC / 3.3V
chan23 mVolt from Hall current sensor ( isolated )
++ but that is only for the original hall sensors,
there are also breakout board what have already a decouple amplifier
let's see what i have here? ACS758 range 50A ( AC DC / 2.5V +- 0.040V*A )

instead of good ( isolated ) HALL sensors can also use SHUNT current sensors,
for a small PS use a INA219
( read 26V DC, 3.2A, I2C link 0x40 (A0 soldered 0x41, A1 soldered 0x44, A0&A1 soldered 0x45 )


adafruit INA219
learn
i run into a few problems, about libs and I2C
copy from bundle:
adafruit-circuitpython-bundle-8.x-mpy-20221104.zip
/lib/adafruit_ina219.mpy
/lib/adafruit_register/...
i disable / and disconnect ADS1115 and connect INA219
at start show the detailed info:
when i connect INA219 Vin+ to 5V (USB) see MQTT
{ 'id': 35, 'dev':'P01', 'Volt': 1.52, 'Amp': 0.09, 'Watt': 0.13, 'Temp': 35.56, 'Vbus': 5.01, 'ShuntAmp': -0.00 }
!! that high side measurement ( by a 3v3 mcu and INA219 ) works !!

code.py
to test it is a other question:
i have a XH-M411 ( DC 3V-35V to DC 5V-45V Boost Converter Board 5A ) ( Vout > V in // only volt indication )

still where the input volt comes from? and what LOAD i have to burn it?
later more
now i setup RPI3B+ as broker ( mosquitto autostart ) and
NODE-RED dashboard ( manual start )
now while the PICO code can start without boker
it will just measure and print
but to connect to broker LATER need a reboot!!
i had to setup mosquitto and change .env in PICO_W to broker 192.168.1.103

so for the NODE-RED MQTT DASH-BOARD
there i did earlier some tricky install ( like admin and user setup and selectable projects! )
i have to dig into again
also new broker setup and new data structure ( topic and data JSON like )
but the main idea is similar to a prior project ( where i saved the /home/pi/.node-red/projects/MYPROJECT/flow.json file )
NO, the copy of the old flow.json over/in a new created /projects/PICOW/ fails and i see a empty flow??? thats bad...
BUT a import ( of file: flow.json from that browser computer ) worked besides i had the 2 "Flow1" ? i did hide the original / empty one.
slowly work on the changes..




now in the MQTT world a ONLINE broker is more useful, if remote dataview or action is required
still the local RPI can be a local dashhboard provider,
unless the node-red is also ONLINE, where just a browser worldwide is needed.
but that is not all the options, how about to see the above local system as local / adhok / fast trend / panel
and from there via the mosquito a bridge is build
doc
tutorial
to a ONLINE MQTT broker ( but first try to find a free / entry account )
* * when a more moderate datarate is required ( as ONLINE that costs money )
possible more easy to make a python bridge code service
tutorial
but slowly: test the PICO_W & INA219 with a
12VDC "S25-12" ( 2.1A ) measured with DMM 12.1VDC without load ( but there is a adjustment poti )
and some RGB LED STRIP driver.
and what i see from INA219 ( in mqttsub ) NOTHING
- - i forget to connect the MINUS of the PICO ( or INA ) with the MINUS of the PS - - LOAD
+ + i think there should be a GND screw connector on the "powerside" of the INA


yes the driver give a flickering RGB LED show, you never know what current you just measure...
i will rearrange the code to measure every second ? and filter volt and current ?
but first from adafruit
there might be a config about avg-ing inside the
besides the INA chip internal averaging i build a
node-red tune app for signal s
and a signal filtered sf = sf *sa + s*sb for Volt Amp Watt with sa + sb = 1.0 and sa send by mqtt for each
for the INA ( now can read 1 sec and filter )



code.py
flows.json
HIST_flows.json
TUNE_flows.json
the filter for Volt Amp Watt start with a moderate 0.8 setting, but can be tuned by mqtt / node-red ui/TUNE
actually target 0.9..
with 1.0 no change come through ( indication freezes )
with 0.0 no filter at all.
add allow remote tuning of the sample time

now that remote mqtt tuning will be lost at reset/boot
and i ask at forum how to do: NVM
example code:
code.py
tools.py
eeprom.py
note: so
* node-red functions are JS,
* pico_w circuit-python code.py
can get easy confused while working on both.
bad esp. JSON lib differences:
JS: print( MYJSON.variable )
PY: print( MYJSON['variable'] )
-4.6- ONLINE EDITOR
https://code.circuitpython.org
is a online editor ( and works here from google chrome via USB ( with some file saving problems )
but from here: https://learn.adafruit.com/getting-started-with-web-workflow-using-the-code-editor
i got the idea that the pico w is just online by wifi local LAN ( like when powered ( usb ) but not by computer )
if circuitpython version is newer and a .env file is there with wifi credentials, but not find that...
800b3 revision info states that works for ESP boards now only, wait and see!
-4.7- Circuit Python update
update to 8.0.0 beta 4
webserver now can do fixIP
-4.8- issue1: ( with 8.0.0b4 ? )
i use any win PC USB port to PICO W
can load UF2 ( if [bootsel] pressed at cabel connetcion ( power up ) )
can develop via Mu
can close Mu and code.py still runs
can plug in USB get win USB connect music and code starts
i follow up on MQTT broker see msg ( now with counter and every 3 sec )
changed code so led ON at boot ( OFF 1 sec for read analogs and send mqtt )
but: when i power up by charger pico w not boot/start
so useless as stand alone tool??
ok, seems some left over prints ( not disabled ) disabled PICO W booting on charger
but need to check more, test code of my diag print ( related to the boot without usb?? )
this seems also only rare booting from charger??
now i use a RESET pb ( over pin 28 pin 30 )
that will try again ( and not need to unplug USB connector ( PC side or PICO board side )
-4.8- issue2: ( with 8.0.0b4 ? )
OS incompatibility
the pico w setup with circuit python 8.0.0 beta4
-a- when setup ( and use Mu 1.1.1) from win 10 : can not use in RPI4 ( no drive opens )
-b- when flash it from RPI and use it with Mu 1.0.3 there and then:
when move to win PC
it detects a bad drive ( and automatically repairs it )
-4.8- issue3: ( with 8.0.0b4 ? )
i2c = busio.I2C(board.GP5, board.GP4) # must use pin
# as SDA1 pin 6 SCL1 pin7 ( SDA SCL SDA1 SCL1 not in dir(board) ?? )
but it works
well, with Circuit Python i feel as a beginner, writing my first arduino sketches 10 years ago ( ARDUINO DUEMILANOVE board )
it is that bad..
besides using python, still do that blocking delay things
time.sleep(10) # ___ wait 10 sec for next job
what is a absolut NO GO for a Programmable Logic Controller thinking,
- - disables the REPL [CTRL][c],
- - delays main jobs like listen to webserver/mqtt incoming...
so, now i do again what i did with my first arduino code
replace all while True : delay() JOB1 with a main loop
+ + what runs as fast as possible
+ + check milli seconds for elapsed time to trigger a timed JOB1() .. or a semi multi tasking JOBx() structure
+ + check x loops counter for fast background checks to catch events
+ + check by big loop counter ( and optional report every 1 million loops the delta time )
for the milli sec i use the
# _____________________________________________________ expect /lib/adafruit_ticks.mpy from adafruit-circuitpython-bundle-8.x-mpy-20221110.zip
from adafruit_ticks import ticks_ms # _________________ also we count the ( not delayed ) loops and report on 1 million loops ( about > 22 sec ???)
code.py
pack some of that learned features into a bigger project
and use a own web-page / article / for it here
end Circuit Python

got it soldered at a mobile repair shop with professional equipment for 1.06$
my eyes already have new plastic lenses, still not good enough for that little things.
i use the RPI4 remote VNC desktop
and there it could make sense not only to use the MINICOM terminal ( to PICPW... )
( and that works remotely also in SSH client terminal )
try for desktop add CUTECOM

in MU python window i see that serial terminal too,
but actually i have problems to stop it [ctrl][c] not work
can not copy strings from there as the ..... refresh too fast and any selection get lost
but with CUTECOM i can start the LOG file.