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: 47
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: 47
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: 47
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: 332
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: 332
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: 47
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: 332
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.