0

Reading analog input data on Huzzah ESP 32 to Adafruit.io
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Reading analog input data on Huzzah ESP 32 to Adafruit.io

by bubblebao on Tue Sep 10, 2019 9:13 am

Hello

I'm using sketch examples from Adafruit IO Arduino > Adafruitio_08_analog_in

trying to read FSR value connected to my Huzzah ESP 32 board and sent the value to adafruit.io

This is my circuit :

IMG_2439.jpg
IMG_2439.jpg (130.2 KiB) Viewed 59 times


and I'm using this code example, but I added wifi connection code in the void setup

Code: Select all | TOGGLE FULL SIZE




// Adafruit IO Analog In Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-analog-input
//
// 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"

//esp 32 board//
#include <sd_defines.h>
#include <sd_diskio.h>
#include <SD.h>


//external wifi setting //
#include <WiFi.h>
const char* ssid     = "FWG-Guest";
const char* password = "Water2018.";

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

// analog pin 0
#define FSR_PIN A0

// FSR state
int current = 0;
int last = -1;

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

void setup() {

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

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

  //connect to wifi //
  WiFi.begin (ssid,password);
  Serial.print ("Connecting to wifi");
  while (!WiFi.status () != WL_CONNECTED) {
    Serial.print (".");
    delay (500);
    }

  Serial.println ("\nconnected to the wifi network");
  Serial.print ("IP address = ");
  Serial.println (WiFi.localIP());

  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  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();

  // grab the current state of the photocell
  current = analogRead(FSR_PIN);

  // return if the value hasn't changed
  if(current == last)
    return;

  // save the current state to the analog feed
  Serial.print("sending -> ");
  Serial.println(current);
  analog->save(current);

  // store last FSR state
  last = current;

  // wait three seconds (1000 milliseconds == 1 second)
  //
  // because there are no active subscriptions, we can use delay()
  // instead of tracking millis()
  delay(3000);
}


and my config.h code below :
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   "bubblebao"
#define IO_KEY        "xxxxx"

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


/*******************************connecting to external WIFI **************************************/

//#include <WiFi.h>;
//const char* ssid     = "FWG-Guest";
//const char* password = "Water2018.";

#define WIFI_SSID   "FWG-Guest"
#define WIFI_PASS   "Water2018."

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


I've also created a feed and a dashboard on adafruit.io to store the sensor reading.

My problem is :

- I didn't get the result as suggested from the tutorial : https://learn.adafruit.com/adafruit-io- ... duino-code especially in the part of connecting to arduino.io

Screenshot 2019-09-10 at 14.05.07.png
Screenshot 2019-09-10 at 14.05.07.png (116.6 KiB) Viewed 59 times


- can't work out connecting my board to external wifi

Please help!

bubblebao
 
Posts: 14
Joined: Tue Aug 13, 2019 7:32 pm

Re: Reading analog input data on Huzzah ESP 32 to Adafruit.i

by millercommamatt on Tue Sep 10, 2019 9:23 am

First, those headers need to be soldered.

Second, use A2. Anything on ADC #2 (see the pinout guide) won't work while the WiFi is active.

millercommamatt
 
Posts: 418
Joined: Tue Jul 31, 2018 4:57 pm

Re: Reading analog input data on Huzzah ESP 32 to Adafruit.i

by brubell on Tue Sep 10, 2019 9:27 am

millercommamatt wrote:First, those headers need to be soldered.

Second, use A2. Anything on ADC #2 (see the pinout guide) won't work while the WiFi is active.


yup - the headers on the ESP32 Huzzah need to be soldered to the pins, see this page for a walk-thru: https://learn.adafruit.com/adafruit-huz ... eaders-3-7

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

Re: Reading analog input data on Huzzah ESP 32 to Adafruit.i

by bubblebao on Tue Sep 10, 2019 9:51 am

Thank you for the replies. I'm still nervous in soldering the board, I thot it could be done withour soldering for prototyping purpose.

bubblebao
 
Posts: 14
Joined: Tue Aug 13, 2019 7:32 pm

Re: Reading analog input data on Huzzah ESP 32 to Adafruit.i

by millercommamatt on Tue Sep 10, 2019 10:16 am

Soldering is required. There won't be a consistent electrical connection otherwise.

If you are nervous about soldering, buy some pin header strips and some prototype board and practice with that. It's a really inexpensive way to practice. It actually takes some effort to make a mistake that can't be corrected.

millercommamatt
 
Posts: 418
Joined: Tue Jul 31, 2018 4:57 pm

Please be positive and constructive with your questions and comments.