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.
Locked
User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

Post by Tom_Henry »

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

# 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 220 times

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

Post by brubell »

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

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

User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

Post by Tom_Henry »

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

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

Post by brubell »

I was unable to get permission to update the firmware.
Could you please post a screenshot of this error?

User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

Post by Tom_Henry »

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 192 times
Direction for Mac Terminal.png
Direction for Mac Terminal.png (59.52 KiB) Viewed 192 times

User avatar
jerryn
 
Posts: 1865
Joined: Sat Sep 14, 2013 9:05 am

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

Post by jerryn »

You need to type:

Code: Select all

ls /dev/tty*
Or

Code: Select all

ls /dev/cu*

User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

Post by Tom_Henry »

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

User avatar
jerryn
 
Posts: 1865
Joined: Sat Sep 14, 2013 9:05 am

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

Post by jerryn »

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

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

User avatar
Tom_Henry
 
Posts: 350
Joined: Wed Aug 26, 2020 8:19 pm

Re: Raspberry Pi Pico RP2040 with WiFi by Brent Rubell

Post by Tom_Henry »

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

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”