0

safe to try? PyPortal using Arduino and Adafruit IO?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

safe to try? PyPortal using Arduino and Adafruit IO?

by Sam43054 on Mon Apr 08, 2019 5:18 pm

I wanted to ask a question before trying-- not knowing if it could brick/lock anything up

(Yes I know there is an example for PyPortal using Adafruit IO with CircuitPython)

I want to use Arduino to code PyPortal to communicate with Adafruit IO


I see that the PyPortal uses WiFiNINA to have the ESP32 work with the internet since the pyPortal has a M4
https://learn.adafruit.com/adafruit-pyp ... -libraries


Is it safe to take the example code below and add "#include <WiFiNINA.h>" at the top to get everything working with the Adafruit IO

Or is something else needed? or is a library being later updated to work with WiFiNINA (ESP32 when used with a M4)

Code: Select all | TOGGLE FULL SIZE
// digital pin 5
#define LED_PIN 5
#include <WiFiNINA.h   <<---- [i]added [/i]
// set up the 'digital' feed
AdafruitIO_Feed *digital = io.feed("digital");

void setup() {
 
  pinMode(LED_PIN, OUTPUT);
 
  // start the serial connection
  Serial.begin(115200);

  // wait for serial monitor to open
  while(! Serial);

  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();

  // set up a message handler for the 'digital' feed.
  // the handleMessage function (defined below)
  // will be called whenever a message is
  // received from adafruit io.
  digital->onMessage(handleMessage);

  // wait for a connection
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io.statusText());
  digital->get();

}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();

}

// this function is called whenever an 'digital' feed message
// is received from Adafruit IO. it was attached to
// the 'digital' feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {

  Serial.print("received <- ");

  if(data->toPinLevel() == HIGH)
    Serial.println("HIGH");
  else
    Serial.println("LOW");


  digitalWrite(LED_PIN, data->toPinLevel());
}

Sam43054
 
Posts: 52
Joined: Tue Jul 12, 2016 10:13 am

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by Sam43054 on Wed Apr 10, 2019 8:02 pm

I have tried to add "#include <WiFiNINA.h>" to the following sketch
It does not work

Any ideas how to get the PyPortal to communicate with Adafruit IO? or is it possible ?

Code: Select all | TOGGLE FULL SIZE
// Adafruit IO Digital Output Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-digital-output
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/

// digital pin 5
#define LED_PIN 5

// set up the 'digital' feed
AdafruitIO_Feed *digital = io.feed("digital");

void setup() {
 
  pinMode(LED_PIN, OUTPUT);
 
  // start the serial connection
  Serial.begin(115200);

  // wait for serial monitor to open
  while(! Serial);

  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();

  // set up a message handler for the 'digital' feed.
  // the handleMessage function (defined below)
  // will be called whenever a message is
  // received from adafruit io.
  digital->onMessage(handleMessage);

  // wait for a connection
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io.statusText());
  digital->get();

}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();

}

// this function is called whenever an 'digital' feed message
// is received from Adafruit IO. it was attached to
// the 'digital' feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {

  Serial.print("received <- ");

  if(data->toPinLevel() == HIGH)
    Serial.println("HIGH");
  else
    Serial.println("LOW");


  digitalWrite(LED_PIN, data->toPinLevel());
}

Sam43054
 
Posts: 52
Joined: Tue Jul 12, 2016 10:13 am

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by Sam43054 on Wed Apr 10, 2019 9:55 pm

Hi

I watched the Wednesday LIVE show that happened to be about the PyPortal so I got on Discord and asked if this is possible

ladyada Said it’s possible and that I should reach out on this page saying that someone on the team would help me get started with adapting PyPortal with Adafruit IO using Arduino

She said Brent can take a look at it later this week .. Quick synopsis: any help would be Appreciative but I am looking to get a value off of Adafruit IO feed (let’s say “digital” and post it on the PyPortal display

There are fabulous tutorials for ESP8266 etc boards I’m Just stuck on how to implement it with WiFiNINA

Again thanks for any help :)

Sam43054
 
Posts: 52
Joined: Tue Jul 12, 2016 10:13 am

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by brubell on Thu Apr 11, 2019 11:54 am

Sam43054 wrote:Hi

I watched the Wednesday LIVE show that happened to be about the PyPortal so I got on Discord and asked if this is possible

ladyada Said it’s possible and that I should reach out on this page saying that someone on the team would help me get started with adapting PyPortal with Adafruit IO using Arduino

She said Brent can take a look at it later this week .. Quick synopsis: any help would be Appreciative but I am looking to get a value off of Adafruit IO feed (let’s say “digital” and post it on the PyPortal display

There are fabulous tutorials for ESP8266 etc boards I’m Just stuck on how to implement it with WiFiNINA

Again thanks for any help :)


Hi sam, I can take a look at working on this tomorrow AM. I'll report my findings back to this thread.

It'd be great to support this in Adafruit IO Arduino, or at least Adafruit MQTT (I'd start there first, as Adafruit IO Arduino uses this library)

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

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by ssejka on Sun Apr 14, 2019 12:31 am

brubell,

Has there been any progress on this? I also would like to use MQTT in the Arduino IDE with my PyPortal. Any help would be appreciated!

Thanks!

ssejka
 
Posts: 4
Joined: Fri Jun 12, 2015 2:07 pm

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by brubell on Tue Apr 16, 2019 1:51 pm

I'm going through this slowly, starting with Adafruit IO MQTT as it is a dependency for Adafruit IO Arduino, but I'll be focusing on connecting to Adafruit IO.

I added support for the PyPortal and other SAMD51 boards as hardware targets this morning.

I just submitted a PR with a new example for securely connecting a PyPortal running Adafruit MQTT to Adafruit IO. Before running this example, make sure to grab the latest ZIP of this library (I have not done a full release yet) and follow the instructions for downloading the correct Arduino libraries here: https://learn.adafruit.com/adafruit-pyportal/setup

PR: https://github.com/adafruit/Adafruit_MQ ... y/pull/153

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

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by Sam43054 on Tue Apr 16, 2019 4:30 pm

Hey

Thanks for the update! I appreciate the work!

I was able to use the example, make a modification to the sketch to use a feed named "digital" and start at 800 and advance every 5 seconds (My adafruit io account has lots of updates so I slowed this down to every 5 seconds)

It has advanced to 1076!

question -- it worked (So it must be what is intended .. ?)

line 45


"Adafruit_MQTT_Publish test = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/digital");"


I changed "test" to "digital"

but I left line 101 alone
Code: Select all | TOGGLE FULL SIZE
if (!test.publish(x++))
  {


AM I correct the feed name only changes around line 45, but line 101 stays the same?



I'll update this once I pay around with it more

Sam43054
 
Posts: 52
Joined: Tue Jul 12, 2016 10:13 am

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by brubell on Tue Apr 16, 2019 4:49 pm

AM I correct the feed name only changes around line 45, but line 101 stays the same?


Yep - this is a publish and subscribe example. So it'll publish x's value to the /digital feed and subscribe to another feed.

Glad you got it working, there's still a bunch to do - please leave a comment on the PR verifying it works.

I'm going to add compatibility for Adafruit AirLift first into here. AIOA next!

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

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by brubell on Mon Apr 29, 2019 5:34 pm

Bumping this as an update - we've added compatibility for AirLift to the latest release of Adafruit IO Arduino

https://github.com/adafruit/Adafruit_IO ... o/releases

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

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by mpc823 on Sun May 19, 2019 6:40 pm

The example adafruit_00_subscribe doesn't seem to work. I get the following error when I try to compile (I've uncommented the #define USE_AIRLIFT):

Code: Select all | TOGGLE FULL SIZE
In file included from C:\Users\Daniel\Documents\ArduinoIDE\arduino-1.8.9\portable\sketchbook\libraries\Adafruit_IO_Arduino\src/AdafruitIO_WiFi.h:22:0,

                 from sketch\config.h:30,

                 from C:\Users\Daniel\AppData\Local\Temp\arduino_modified_sketch_140413\adafruitio_00_publish.ino:18:

C:\Users\Daniel\Documents\ArduinoIDE\arduino-1.8.9\portable\sketchbook\libraries\Adafruit_IO_Arduino\src/wifi/AdafruitIO_AIRLIFT.h: In member function 'virtual void AdafruitIO_AIRLIFT::_connect()':

C:\Users\Daniel\Documents\ArduinoIDE\arduino-1.8.9\portable\sketchbook\libraries\Adafruit_IO_Arduino\src/wifi/AdafruitIO_AIRLIFT.h:163:16: error: 'class WiFiClass' has no member named 'setPins'

           WiFi.setPins(_ssPin, _ackPin, _rstPin, _gpio0Pin, _wifi);

                ^

In file included from C:\Users\Daniel\AppData\Local\Temp\arduino_modified_sketch_140413\adafruitio_00_publish.ino:18:0:

sketch\config.h: At global scope:

config.h:42:90: error: 'ESP32_RESETN' was not declared in this scope

   AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);

                                                                                          ^

config.h:42:104: error: 'ESP32_GPIO0' was not declared in this scope

   AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);

                                                                                                        ^

exit status 1
'ESP32_RESETN' was not declared in this scope


mpc823
 
Posts: 39
Joined: Thu May 05, 2016 9:10 am

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by brubell on Mon May 20, 2019 9:48 am

Follow the guide on https://learn.adafruit.com/adafruit-io- ... io-library

If you're still having an issue, please paste your config.h file along with the library versions you're using in a reply below.

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

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by mpc823 on Mon May 20, 2019 6:31 pm

This actually is exactly what I had done. My error message and config.h file are below. I am using Arduino 1.8.9. Arduino HTTP 0.4.0, Adafruit IO Arduino 3.1.0, and Adafruit MQTT 1.0.3.

I noticed that in my variants file for the PyPortal_M4, I have the following definitions:

Code: Select all | TOGGLE FULL SIZE
/* WiFi interfaces */
#define SerialNina      Serial1
#define SPIWIFI         SPI
#define NINA_GPIO0      6
#define NINA_RESETN     7
#define SPIWIFI_SS      8
#define SPIWIFI_ACK     5
#define SPIWIFI_RESET   7
#define SerialESP32     Serial1


Note that instead of ESP32_RESETN I have NINA_RESETN, and instead of ESP32_GPIO0 I have NINA_GPIO0. I have even tried updating all my board packages, but the problem is still there. I'm not sure how to get the version of the variants file, but the Adafruit SAMD boards is version 1.4.1.

Here's the error message and the config.h file (with my info XXX-ed out).

Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.9 (Windows 8.1), Board: "Adafruit PyPortal M4 (SAMD51), Enabled, 120 MHz (standard), Small (-Os) (standard), 24 MHz (standard), 50 MHz (standard)"

In file included from C:\Users\Daniel\Documents\ArduinoIDE\arduino-1.8.9\portable\sketchbook\libraries\Adafruit_IO_Arduino\src/AdafruitIO_WiFi.h:22:0,

                 from sketch\config.h:30,

                 from C:\Users\Daniel\AppData\Local\Temp\arduino_modified_sketch_979286\adafruitio_00_publish.ino:18:

C:\Users\Daniel\Documents\ArduinoIDE\arduino-1.8.9\portable\sketchbook\libraries\Adafruit_IO_Arduino\src/wifi/AdafruitIO_AIRLIFT.h: In member function 'virtual void AdafruitIO_AIRLIFT::_connect()':

C:\Users\Daniel\Documents\ArduinoIDE\arduino-1.8.9\portable\sketchbook\libraries\Adafruit_IO_Arduino\src/wifi/AdafruitIO_AIRLIFT.h:163:16: error: 'class WiFiClass' has no member named 'setPins'

           WiFi.setPins(_ssPin, _ackPin, _rstPin, _gpio0Pin, _wifi);

                ^

In file included from C:\Users\Daniel\AppData\Local\Temp\arduino_modified_sketch_979286\adafruitio_00_publish.ino:18:0:

sketch\config.h: At global scope:

config.h:42:90: error: 'ESP32_RESETN' was not declared in this scope

   AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);

                                                                                          ^

config.h:42:104: error: 'ESP32_GPIO0' was not declared in this scope

   AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);

                                                                                                        ^

exit status 1
'ESP32_RESETN' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


Code: Select all | TOGGLE FULL SIZE
/************************ Adafruit IO Config *******************************/

// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME   "XXXX"
#define IO_KEY        "XXXX"

/******************************* WIFI **************************************/

// the AdafruitIO_WiFi client will work with the following boards:
//   - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
//   - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
//   - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
//   - Feather M0 WiFi -> https://www.adafruit.com/products/3010
//   - Feather WICED -> https://www.adafruit.com/products/3056
//   - Adafruit PyPortal -> https://www.adafruit.com/product/4116
//   - Adafruit Metro M4 Express AirLift Lite -> https://www.adafruit.com/product/4000
//   - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201

#define WIFI_SSID   "XXXXX"
#define WIFI_PASS   "XXXXX"

// uncomment the following line if you are using airlift
#define USE_AIRLIFT

// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

#ifdef USE_AIRLIFT
  // Configure the pins used for the ESP32 connection
  #if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
    // Don't change the names of these #define's! they match the variant ones
    #define SPIWIFI SPI
    #define SPIWIFI_SS 10  // Chip select pin
    #define SPIWIFI_ACK 9  // a.k.a BUSY or READY pin
    #define ESP32_RESETN 6 // Reset pin
    #define ESP32_GPIO0 -1 // Not connected
  #endif
  AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
#else
  AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
/******************************* FONA **************************************/

// the AdafruitIO_FONA client will work with the following boards:
//   - Feather 32u4 FONA -> https://www.adafruit.com/product/3027

// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);

/**************************** ETHERNET ************************************/

// the AdafruitIO_Ethernet client will work with the following boards:
//   - Ethernet FeatherWing -> https://www.adafruit.com/products/3201

// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

mpc823
 
Posts: 39
Joined: Thu May 05, 2016 9:10 am

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by brubell on Tue May 21, 2019 10:36 am

Looks like this PR didn't get released which changed the pin config. for the PyPortal to match the config.h (https://github.com/adafruit/ArduinoCore ... 1d3bd1e7d1). I'll look into why this wasn't released.


For now, I just tested a sample pin configuration this morning. You'll want to place this in your config.h file under WIFI.

Code: Select all | TOGGLE FULL SIZE
// uncomment the following line if you are using airlift
#define USE_AIRLIFT

// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

#ifdef USE_AIRLIFT
    #define SPIWIFI SPI
    #define SPIWIFI_SS 10  // Chip select pin
    #define SPIWIFI_ACK 9  // a.k.a BUSY or READY pin
    #define ESP32_RESETN 7 // Reset pin
    #define ESP32_GPIO0 6 // Not connected
    #define NINA_GPIO0 ESP32_GPIO0
    #define NINA_RESETN ESP32_RESETN
  AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
#else
  AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif

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

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by mpc823 on Tue May 21, 2019 5:29 pm

Unfortunately, now I get the following error:

Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.9 (Windows 8.1), Board: "Adafruit PyPortal M4 (SAMD51), Enabled, 120 MHz (standard), Small (-Os) (standard), 24 MHz (standard), 50 MHz (standard)"

Build options changed, rebuilding all
In file included from C:\Users\Daniel\Documents\ArduinoIDE\arduino-1.8.9\portable\sketchbook\libraries\Adafruit_IO_Arduino\src/AdafruitIO_WiFi.h:22:0,

                 from sketch\config.h:30,

                 from C:\Users\Daniel\AppData\Local\Temp\arduino_modified_sketch_674812\adafruitio_00_publish.ino:18:

C:\Users\Daniel\Documents\ArduinoIDE\arduino-1.8.9\portable\sketchbook\libraries\Adafruit_IO_Arduino\src/wifi/AdafruitIO_AIRLIFT.h: In member function 'virtual void AdafruitIO_AIRLIFT::_connect()':

C:\Users\Daniel\Documents\ArduinoIDE\arduino-1.8.9\portable\sketchbook\libraries\Adafruit_IO_Arduino\src/wifi/AdafruitIO_AIRLIFT.h:163:16: error: 'class WiFiClass' has no member named 'setPins'

           WiFi.setPins(_ssPin, _ackPin, _rstPin, _gpio0Pin, _wifi);

                ^

exit status 1
Error compiling for board Adafruit PyPortal M4 (SAMD51).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

mpc823
 
Posts: 39
Joined: Thu May 05, 2016 9:10 am

Re: safe to try? PyPortal using Arduino and Adafruit IO?

by brubell on Wed May 22, 2019 10:13 am

Code: Select all | TOGGLE FULL SIZE
C:\Users\Daniel\Documents\ArduinoIDE\arduino-1.8.9\portable\sketchbook\libraries\Adafruit_IO_Arduino\src/wifi/AdafruitIO_AIRLIFT.h:163:16: error: 'class WiFiClass' has no member named 'setPins'


Are you using the adafruit WiFiNiNa, or the Arduino library?

Click download zip on this repository, not the releases page: https://github.com/adafruit/WiFiNINA/

I added instructions on installing the adafruit branch to the learn guide.

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

Please be positive and constructive with your questions and comments.