Cheap IOT Device in Minutes and Without Writing Any Code Using Raspberry Pico Pi W

by Fab64 in Circuits > Arduino

1198 Views, 3 Favorites, 0 Comments

Cheap IOT Device in Minutes and Without Writing Any Code Using Raspberry Pico Pi W

FKV92RZL6PI3BI8.jpg

The new Raspberry Pi Pico W (which includes Wi-Fi support) offers a huge opportunity to make cheap iOT devices. The microcontroller market already offers cheap and largely available microcontrollers (like ESP8622 and ESP32) but the Pico W strength is that Raspberry provides a lot of well written documentation. This helps to save a lot of development time and hassles. Who spent hours trying which ESP8266/32 pin is which and figuring out which pin is better to be left alone at boot, knows what we are talking about.

On the other hand, Arduino Manager is an iOS / macOS and watchOS application, based on configurable Widgets, which provides easy way to present data coming from the microprocessor (LED, Display, Graphs, etc.) and control it remotely (Switch, Know, Slider, etc.). The strengths of Arduino Manager are:

  • No registration / no cloud: You can control your devices without registering to any cloud service (now free, but tomorrow?). Your data just go back and forth between your devices only.
  • Code Generators: Arduino Manager provides (for an additional price) two code generators which in most cases take care of everything from communication layer to microcontroller's pins, minimizing the code you have to write and providing help fine tune your final solution.

This is a guide to use Arduino Manager to create a simple iOT device based on Raspberry Pico Pi W. You can start from here to develop your own ideas.

Disclaimer: I am the designer and developer of Arduino Manager.

Let get started.

Supplies

  • Raspberry Pico Pi W
  • Arduino Manager
  • Arduino Manager Code Generator - optional
  • Arduino Manager PIN Code Generator - optional
  • Thonny
  • Some male-male jumper wires
  • 1 x Breadboard
  • 1 x LED
  • 1 x 330 ohm resistor
  • 1 x 10K ohm resistor
  • 1 x tactile push button
  • 1 x 10K ohm potentiometer
  • 1 x SD Card reader

The Device

PicoW_iOT_bb.png
PicoW_iOT_schem.png

Since this tutorial is focused on showing how to create a cheap iOT device with a minimal effort, we get start with:

  • A potentiometer connected to an analog input
  • A tactile switch connected to a digital input
  • An LED connected to a digital output

This is the starting point to connect to the iOT any analog sensor (eg thermistors, strength gages, photoresistors, accelerometers, gyroscopes, etc.), digital sensor (eg switches, etc.) or BJT/MOS drivers to control relays, motors etc.

With a minimal additional effort any SPI or I2C device can be connected as well.

The electric diagram and the breadboard diagram are show in the attached figures. The card reader can be ignored at this moment.

Raspberry Pico Pi W Development Environment

We assume that:

  • Raspberry Pi Pico W has MicroPython installed
  • Thonny is installed on the development computer
  • Pico W is connected to the development computer and MicroPython programs can be uploaded and ran

All the required information can be found here:


Arduino Manager Setup

Arduino Manager can be bought from the Apple App Store:

The following instructions are for the macOS version but they can be applied to the iOS version almost unchanged.

In order to communicate with the iOT device Arduino Manager requires only to have a TCP/IP connection (or a Bluetooth BLE connection, not covered here). Anyway, in order to download the generated code or to download some additional software is required that the macOS or iOS device is signed in to the iCloud using an Apple ID. Please, verify that the development computer is signed in to iCloud (more information).

Arduino Manager can generate the iOT device's code both for Arduino IDE (C++) and Micropython. This instructable is based on Micropython. Hence the first to do is downloading some support code for MicroPython.

  1. Start Arduino Manager
  2. In the left menu click on MicroPython Support Code and then on Raspberry Pi Pico W
  3. Open the iCloud Driver on the development computer
  4. Enter the Arduino Manager folder
  5. Enter the MicroPython folder and then the Pico_w folder
  6. Copy the following file to the Pico W:
  • ArduinoManager.py
  • logging.py
  • sdcard.py

Create the First Widget List

Screen Shot 2022-07-24 at 6.47.16 PM.png
Widget List.png

The Widget List is a collection of Widgets which allows to interact with the Pico W. To create the first Widget List procede as follows:

  1. In the left menu click Widget Lists
  2. Click New
  3. Enter the name of the new Widget List: My iOT device
  4. The Widget List can be stored locally or on the iCloud. When stored on the iCloud it is shared and accessible from any macOS or iOS device signed in with the same Apple ID. The Widget List can be move to or from the iCloud later
  5. Click Ok
  6. Select the just created Widget List
  7. From the left menu click Widgets

Now the right side of the app shows an empty grid where the Widgets can be placed:

  1. Switch to edit (bottom right side of the screen)
  2. Click on a free position
  3. The list of available Widgets shows up
  4. Select the Display Widget. A new Widget is added to the grid
  5. In place of the ?, enter the Widget's name: Potentiometer
  6. Switch off the edit mode


Generate the Code

Code Generator Configuration.png

This Step is about generating the MicroPython in order to read the voltage value at the Potentiometer's wiper position using the ADC provided by the Pico Pi W.

  1. In the left menu click Code Generator
  2. Enter the required information
  • Project Name: My iOT device
  • Board: Raspberry Pico W
  • Language: MicroPython
  • IP: 192.168.1.70 (This is the IP address which will be assigned to the iOT device, the value has to be compatible with the configuration of the Wi-Fi network used)
  • Port: 90 (This is the IP port used by the iOT device)
  • Netmask: 255.255.255.0 (This defines the subnetwork to which the iOT is connected, usually 255.255.255.0 is fine)
  • Gateway: 192.168.1.1 (This is the address of the Gateway used to connect the network to internet, the value has to be compatible with the configuration of the Wi-Fi network used)
  • SSID: Enter the name of the network the iOT device is connected to. The macOS or iOS device has to be connected to the same network (more information available in the Arduino Manager's documentation provided directly into the app).
  • Select Connection and Disconnection callbacks.
  • Click Generate - If the Code Generator has not been purchased yet, Arduino Manager requests to buy it.

The MicroPython code has been generated.

Copy the Generated Code and Run It

iOT Device started.png

The generated code is available clicking on Generated Code from the left menu. It can be copied and pasted to Thonny.

Alternatively, the code is available in the iCloud Driver's folder: Arduino Manager -> My_iOT_Device. Use Thonny to open the generated code, copy it to Pico Pi and run it.

If everything is correct, the Thonny shell should show messages similar to the attached figure.

The iOT device is up and running.

Create the IOT Device Connection in Arduino Manager and Connect to the Device

New Connection.png
Connection Configuration.png

In order to connect Arduino Manager to the iOT device, a new connection has to be created:

  1. Click Connections in the left menu
  2. New Wi-Fi connection
  3. Enter the following information:
  • Name: My iOT Device
  • Ip: 192.168.1.70 (or whatever address entered when the code was generated)
  • Port: 90 (or whatever number entered when the code was generated)

and click Ok.

Open the Widget List (click Widgets) and then open the Grid Configuration (top right side of the screen) and select the just selected connection in order to use it in this grid.

Please note:

  • Can be defined a different number of Widgets for each available Widget page
  • Each Widget page can connect to a different board and each connection can be activated independently

To connect Arduino Manager to Pico Pi W click on the plug icon in the left lower side of the screen. If everything works as expected the blue connection indicator turns on.

Arduino Manager is connected to Pico W but nothing happens. The Generated Code take care of connecting Pico W to the Wi-Fi network, to transfer data back and forth between Pico W and the macOS / iOS device but still nothing has been done to read the voltage at the potentiometer.

The code to read the voltage at potentiometer can be manually added and the Arduino Manager documentation provides all you need in order to do that.

The Pin Code Generator however allows to save a lot of time and effort.

Using the Pin Code Generator Instead of Writing Code

Generate Display.png

In order to generate the code to read voltage at potentiometer, follow these steps:

  1. Click Code Generator
  2. Select the My_iOT_Device
  3. Click Pins
  4. The middle column contains all the Widgets in the list
  5. Select the Display Widget
  6. Since the potentiometer is connected to PIN 26, select it
  7. Enter 100, to read the potentiometer every 100ms
  8. Select Input Preprocess Function. This function will convert the raw value read by the Pico W's ADC into voltage
  9. Click Generate

In Thonny locate the preprocessDisplayPotentiometer function and change it as follows:

def preprocessDisplayPotentiometer(value):
  ret = value
  # Start your code (preprocessDisplayPotentiometer) #
  ret = value * 3.3 / 65535.0 
  # End your code #
  return ret

The added code converts the raw value provided by the Pico W's ADC into voltage.

Note that everything added between the tags

# Start your code

and

# End your code #

is unchanged by the Code Generator at next run.

  1. Run the changed code
  2. Get back to Arduino Manager and connect to Pico W
  3. Now the Display Widget shows up the voltage at potentiometer's wiper.

Completing the Widget List and Code Generation

Base Final Grid .png
Base Final Pins Configuration.png
Push Button Configuration.png

The iOT device is now able to periodically read an analog quantity, process it and send it to the macOS/iOS device (when connected).

Next steps are for working with the Digital quantities.

  1. Back in Arduino Manager, click Widgets and then enter in Edit mode
  2. Click in a free position and select a Switch Widget
  3. Name it Switch 1
  4. Click on the Configuration icon. The variable associated with the Switch Widget is switch_1. This is what has to be used in the code to receive the state of this switch in the Pico W code.
  5. Change the variable to: Switch and then Ok
  6. Click in another free position and add a Push Button Widget and name it Push Me (or whatever you like)
  7. Open the Push Button configuration and change the variable to Switch. You can also change the Button color if you like.
  8. Click on another free space, add LED Widget and name it: Pressed

The attached figure shows the final Widget List configuration.

Now the Widget List is completed. A new code generation is required to account for the new Widgets.

  1. Click Code Generator and select My_iOT_Device project
  2. Click Pins
  3. Select the Switch 1 Widget
  4. Since the Yellow LED is wired to GP14, select Pin: 14. All the other options can be left unchanged
  5. Select the Push Me Widget and select Pin: 14 as well.
  6. Select the Pressed Widget, since the tactile switch is wired to GP15, select PIN: 15. Final Pin configurations are show in the attached Figure.
  7. Click Generate to actually generate the code

Test Everything

Watch 1.png
Watch 2.png
Cheap IOT Device using Pico Pi W. No code required.

The iOT device has now all the planned feature. To test it:

  1. Run the last generated code from Thonny
  2. Get back to Arduino Manager and connect to Pico W
  3. Display Widget shows up the voltage at potentiometer's wiper
  4. Touching the Switch Widget, the Yellow LED on the device turns on and off
  5. Switch off the Yellow LED, then Pushing the Push Button Widget on Arduino Manager, the Yellow LED turns on and stay on until the Push Button is released
  6. Pushing the button on the device, the LED Widget turns on

With a minimum practice in using Arduino Manager and the Code Generators, making this device is matter of minutes and practically no code writing is required.

Arduino Manager also provides an WatchOS version, hence the iOT device can be controlled directly from the Apple Watch.

SD Card Reader for Storing Data - Data Logging

Logged Data Graph configuration.png
Logged Data Graph.png

Many iOT Devices require to store measurement data (e.g. an energy monitor may need to store measured energy over time). Arduino Manager provides a quick and easy way to do that:

  1. Wire an SD Card Reader as shown in the electric diagram shown before
  2. Go to Arduino Manager, open the My iOT device widget list and put it in edit mode
  3. Add a Logged Data Graph Widget and name it data
  4. Go to Code Generator and open the My_iOT_Device project
  5. Click Logged Data Graphs
  6. Select the Data graph
  7. Enter V for the Label 1 and R for Label 2. These are the two quantities that will be shown on the graph
  8. Enter 2 for the Sampling Period
  9. Enter 100 for the Max Number of Samples
  10. Click Generate
  11. Open the new generated code in Thonny

Once more, instead of using the Code Generator, the same code can be written manually. This requires more time and some debugging effort.

Next step is define what Arduino Manager has to store in the SD Card:

  • Some additional code has been automatically added to manage the SD Card and to manage the Graph
  • Locate the doWork function
  • Change the function as show down here:
async def doWork():
  ...
  ...
  # Start your code (doWork) #

  dataV = potentiometer
  dataR = random.uniform(-10, 10)

  # End your code #
  return

The variable dataV will be stored with the voltage at the potentiometer wiper and the variable dataR with a random value. Nothing else have to be done.

  • Run the code on Pico W
  • Go to Arduino Manager and connect to Pi W
  • Double Click on the Data Graph to zoom it
  • Click on Refresh icon to load data
  • Data are loaded and they can be horizontally scrolled (see attached figure)

Experimenting Other Widget

Arduino Manager provides more than 30 different Widgets which may accommodate any iOT device's requirement. The documentation, directly from the app, contains all the information to use them even without the Code Generators.

Experimenting with the Widgets is the best way to get confidence with Arduino Manager.

Cost Analysis

The title of this Instructable includes the word cheap. How cheap is to make this iOT device? Down here some numbers:

  • Raspberry Pico Pi W: $6.00 (cost for each device built)
  • Arduino Manager: $10.99 (can be used for more devices and a unlimited number of projects)
  • Code Generator: $6.99 (can be used for an unlimited number of projects)
  • PIN Code Generator: $6.99 (can be used for an unlimited number of projects)
  • Other Parts: ~$10.00

Then, you can build the first iOT Device for about $40, all the others for about $16.