0

Raspberry Pi Pico RP2040 with WiFi by Brent Rubell
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

by Tom_Henry on Sat Jul 24, 2021 8:08 pm

Quickstart IoT - Raspberry Pi Pico RP2040 with WiFi
By Brent Rubell

https://learn.adafruit.com/quickstart-r ... dafruit-io

I have set up the above project and am having issues with the code.py on the above linked page.

I have attached a copy of the slightly modified code.py that I used. I added 2 print statements to see where the code is working and not working.

The code.py makes it to the print Tom Henry.1 as you can see below.

The code problem area is under the While True section just after printing Tom Henry.1.


code.py output:

Connecting to WiFi...
Connected!

Connecting to Adafruit IO...
Connected to Adafruit IO!

Subscribed to Tom_Henry/f/led with QOS level 0

Tom Henry.1

Traceback (most recent call last):
File "code.py", line 112, in <module>
File "code.py", line 106, in <module>
File "adafruit_io/adafruit_io.py", line 215, in loop
File "adafruit_minimqtt/adafruit_minimqtt.py", line 813, in loop
File "adafruit_minimqtt/adafruit_minimqtt.py", line 831, in _wait_for_msg
File "adafruit_minimqtt/adafruit_minimqtt.py", line 826, in _wait_for_msg
File "adafruit_minimqtt/adafruit_minimqtt.py", line 923, in _sock_exact_recv
MMQTTException: Unable to receive 1 bytes within 60 seconds.

Code done running.

I have also attached a screenshot of the CIRCUITPY drive showing the lib.


I would most appreciate any suggestions on what you think might need to be fixed or changed
.
Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: Brent Rubell for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
from microcontroller import cpu
import board
import busio
from digitalio import DigitalInOut
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_minimqtt.adafruit_minimqtt as MQTT
from adafruit_io.adafruit_io import IO_MQTT

### WiFi ###

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

# Raspberry Pi RP2040
esp32_cs = DigitalInOut(board.GP13)
esp32_ready = DigitalInOut(board.GP14)
esp32_reset = DigitalInOut(board.GP15)

spi = busio.SPI(board.GP10, board.GP11, board.GP12)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets)

# Configure the RP2040 Pico LED Pin as an output
led_pin = DigitalInOut(board.LED)
led_pin.switch_to_output()

# Define callback functions which will be called when certain events happen.
# pylint: disable=unused-argument
def connected(client):
    # Connected function will be called when the client is connected to Adafruit IO.
    print("Connected to Adafruit IO! ")


def subscribe(client, userdata, topic, granted_qos):
    # This method is called when the client subscribes to a new feed.
    print("Subscribed to {0} with QOS level {1}".format(topic, granted_qos))


# pylint: disable=unused-argument
def disconnected(client):
    # Disconnected function will be called when the client disconnects.
    print("Disconnected from Adafruit IO!")


def on_led_msg(client, topic, message):
    # Method called whenever user/feeds/led has a new value
    print("New message on topic {0}: {1} ".format(topic, message))
    if message == "ON":
        led_pin.value = True
    elif message == "OFF":
        led_pin.value = False
    else:
        print("Unexpected message on LED feed.")


# Connect to WiFi
print("Connecting to WiFi...")
wifi.connect()
print("Connected!")

# Initialize MQTT interface with the esp interface
MQTT.set_socket(socket, esp)

# Initialize a new MQTT Client object
mqtt_client = MQTT.MQTT(
    broker="io.adafruit.com",
    username="Tom_Henry",
    password="aio_jfOu45Ii5G1NVxQPMg2M5Y4p2YMv",
)

# Initialize an Adafruit IO MQTT Client
io = IO_MQTT(mqtt_client)

# Connect the callback methods defined above to Adafruit IO
io.on_connect = connected
io.on_disconnect = disconnected
io.on_subscribe = subscribe

# Set up a callback for the led feed
io.add_feed_callback("led", on_led_msg)

# Connect to Adafruit IO
print("Connecting to Adafruit IO...")
io.connect()

# Subscribe to all messages on the led feed
io.subscribe("led")

print("Tom Henry.1")

prv_refresh_time = 0.0
while True:
    # Poll for incoming messages
    try:
        io.loop()
        print("Tom Henry.2")
    except (ValueError, RuntimeError) as e:
        print("Failed to get data, retrying\n", e)
        wifi.reset()
        io.reconnect()
        continue
    # Send a new temperature reading to IO every 30 seconds
    if (time.monotonic() - prv_refresh_time) > 30:
        # take the cpu's temperature
        cpu_temp = cpu.temperature
        print("cpu.temperature")
        # truncate to two decimal points
        cpu_temp = str(cpu_temp)[:5]
        print("CPU temperature is %s degrees C" % cpu_temp)
        # publish it to io
        print("Publishing %s to temperature feed..." % cpu_temp)
        io.publish("temperature", cpu_temp)
        print("Published!")
        prv_refresh_time = time.monotonic()


Attachments
Tom Henry.png
Tom Henry.png (71.49 KiB) Viewed 118 times

Tom_Henry
 
Posts: 101
Joined: Wed Aug 26, 2020 8:19 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

by brubell on Mon Jul 26, 2021 9:29 am

First, try upgrading the firmware on your AirLift. Below are the RP2040-specific instructions:

https://learn.adafruit.com/upgrading-es ... t-firmware

brubell
 
Posts: 1508
Joined: Fri Jul 17, 2015 10:33 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

by Tom_Henry on Mon Jul 26, 2021 10:33 pm

Brent,

I tried to update the firmware for the Pico RP2040 but ran into a problem on my Mac where there was a problem with getting permissions. I was unable to get permission to update the firmware. So, I will go back to this boot loader: adafruit-circuitpython-adafruit_feather_rp2040-en_US-6.3.0.uf2 and use the CIRCUITPY for other projects.

Tom Henry

Tom_Henry
 
Posts: 101
Joined: Wed Aug 26, 2020 8:19 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

by brubell on Tue Jul 27, 2021 10:08 am

I was unable to get permission to update the firmware.


Could you please post a screenshot of this error?

brubell
 
Posts: 1508
Joined: Fri Jul 17, 2015 10:33 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

by Tom_Henry on Tue Jul 27, 2021 12:58 pm

Ok, here is a far as I could go:

1. First screenshot gives me directions for Mac Terminal which I followed.

2. Second screenshot tells me permission denied.

Tom Henry
Attachments
Mac Terminal screenshot.png
Mac Terminal screenshot.png (80.7 KiB) Viewed 90 times
Direction for Mac Terminal.png
Direction for Mac Terminal.png (59.52 KiB) Viewed 90 times

Tom_Henry
 
Posts: 101
Joined: Wed Aug 26, 2020 8:19 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

by jerryn on Tue Jul 27, 2021 1:07 pm

You need to type:
Code: Select all | TOGGLE FULL SIZE
ls /dev/tty*

Or
Code: Select all | TOGGLE FULL SIZE
ls /dev/cu*

jerryn
 
Posts: 1539
Joined: Sat Sep 14, 2013 9:05 am

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

by Tom_Henry on Tue Jul 27, 2021 3:02 pm

Brent,

Ok, that worked. I got this.

Last login: Tue Jul 27 09:47:39 on ttys000
tomhenry@Sir-Thomas ~ % ls /dev/cu*
/dev/cu.Bluetooth-Incoming-Port /dev/cu.usbmodem0000000000001
tomhenry@Sir-Thomas ~ %

Then I moved on in the directions and downloaded a file called: NINA_W102-1.7.4.bin

I tried the following Mac apps to unzip this bin file:

Decompressor

Extract Any File

RAR Extractor

Stuffit Expander

The Unarchiever

NONE of them would unzip the file.

What kind of file is this .bin file?

Any suggestion on an app that will unzip this bin file?

Thanks,

Tom Henry

Tom_Henry
 
Posts: 101
Joined: Wed Aug 26, 2020 8:19 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

by jerryn on Tue Jul 27, 2021 3:38 pm

You do not "unzip" the .bin file. It is uploaded to the Airlift board following these instructions;
https://learn.adafruit.com/upgrading-esp32-firmware/upgrade-rp2040-airlift-firmware

Note: I do not represent Adafruit, Just trying tp help.

jerryn
 
Posts: 1539
Joined: Sat Sep 14, 2013 9:05 am

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

by Tom_Henry on Tue Jul 27, 2021 6:57 pm

Ok, I went as far as I could go. I was unable to upgrade the firmware.

This is way to complicated for a firmware upgrade.

I will just use this with CircuitPython with some other projects.

Thanks for your suggestions.

Tom Henry

Tom_Henry
 
Posts: 101
Joined: Wed Aug 26, 2020 8:19 pm

Please be positive and constructive with your questions and comments.