Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for float formatting on Arduino UNO Wifi Rev. 2 #97

Merged
merged 2 commits into from Nov 13, 2019

Conversation

kintel
Copy link
Contributor

@kintel kintel commented Nov 8, 2019

This PR adds support for float formatting on Arduino UNO Wifi Rev. 2.
Since that Arduino variant uses the "megaAVR" core, which has much of the same limitations as regular AVR cores, the ARDUINO_ARCH_AVR preprocessor check wasn't sufficient to catch this.

This issue was discovered by using said board to post decimal values to Adafruit IO.

Note: This does not add support for board type and board ID - these will still be "unknown" as today.

@brentru
Copy link
Member

brentru commented Nov 8, 2019

@kintel Thanks for adding this, looks good. I will test this on Monday (I have a Uno WiFi Rev2 at my desk).

Note: This does not add support for board type and board ID - these will still be "unknown" as today.

I added an issue to address this here: #98

@brentru
Copy link
Member

brentru commented Nov 11, 2019

@kintel Compiles OK on my end but I think my pinouts for the ESP32 are incorrect - Could you provide me with two things before I test again:

  1. Could you please provide the example code (both the sketch .ino and the config.h file) you used, as a comment below?
  2. Could you edit library.properties to bump the version (https://github.com/adafruit/Adafruit_IO_Arduino/blob/master/library.properties#L2) from 3.2.2 to 3.2.3? Then, add and commit that file to this pull request.

@kintel
Copy link
Contributor Author

kintel commented Nov 13, 2019

@brentru Yeah, this probably warrants an example as there are some assumptions being made in the existing examples about how groups of preprocessor symbols always being defined together.

@kintel
Copy link
Contributor Author

kintel commented Nov 13, 2019

// Adafruit IO Publish Example
//
// 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 *******************************/

// this int will hold the current count for our sketch
float float_count = 0;

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

void setup() {

  // start the serial connection
  Serial.begin(115200);

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

  Serial.print("Connecting to Adafruit IO");

  // connect to io.adafruit.com
  io.connect();

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

  // we are connected
  Serial.println();
  Serial.println(io.statusText());

}

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();

  // save count to the 'counter' feed on Adafruit IO
  Serial.print("sending -> ");
  Serial.println(float_count);
  counter->save(float_count);

  // increment the count by 0.1
  float_count+=0.1;

  // Adafruit IO is rate limited for publishing, so a delay is required in
  // between feed->save events. In this example, we will wait three seconds
  // (1000 milliseconds == 1 second) during each loop.
  delay(3000);

}

@kintel
Copy link
Contributor Author

kintel commented Nov 13, 2019

/************************ 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   "your_username"
#define IO_KEY        "your_key"

/******************************* 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
//   - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
//   - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
//   - Arduino Uno WiFi Rev. 2

#define WIFI_SSID   "your_ssid"
#define WIFI_PASS   "your_pass"

// 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"

#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)
  // Configure the pins used for the ESP32 connection
  #if defined(ARDUINO_AVR_UNO_WIFI_REV2)
    // Note: Arduino Uno WiFi Rev. 2 is essentially an integrated Airlift board
    #define SPIWIFI SPI
  #endif
  #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 NINA_ACK 9    // a.k.a BUSY or READY pin
    #define NINA_RESETN 6 // Reset pin
    #define NINA_GPIO0 -1 // Not connected
  #endif
  AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, NINA_ACK, NINA_RESETN, NINA_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);

@kintel
Copy link
Contributor Author

kintel commented Nov 13, 2019

@brentru My above example may be nice to add as a proper example btw.
The only trick was to specifically check for the Uni Wifi Rev. 2 as it already have most of the needed defines.

@brentru
Copy link
Member

brentru commented Nov 13, 2019

@kintel LGTM, pulling in

@brentru brentru merged commit 23985c6 into adafruit:master Nov 13, 2019
@kintel kintel deleted the uno-wifi branch November 13, 2019 15:02
@kintel
Copy link
Contributor Author

kintel commented Nov 13, 2019

Thanks for rapid turnaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants