Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Need help sending analog voltage input to IO dashboard
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Need help sending analog voltage input to IO dashboard

by bigjoncop on Wed Mar 04, 2020 4:26 pm

I just started using Adafruit IO have been successfully able to send data to my dashboard. Now I'm trying to send an analog input to my dashboard and keep getting error after error in Arduino IDE. I just have two volts going to a0 oh my esp8266 and I'm trying to send that to my dashboard.

I tried to take the Adafruit IO example sketch 4 analog input which is written for a photocell project and tried to modify it just to send a a0 input to the dashboard but can't seem to get the code correct for IDE to upload it to my Arduino.

I know where the code has to be placed within the sample sketch no matter how I try to write it it just fails to upload. Can somebody please show me the lines of code I have to enter to send that value to my dashboard. I'm a hardware guy I have no patience for coding and just get super frustrated. I can write the code that needs to be written in order to have it printed in my serial monitor I just can't seem to get it into Adafruit IO sketch.

THX u..

I'm currently at work. When I get home I will attach the code I am trying to use. Foothill gun if anyone help be greatly appreciated

bigjoncop
 
Posts: 4
Joined: Wed Mar 04, 2020 7:01 am

Re: Need help sending analog voltage input to IO dashboard

by dastels on Wed Mar 04, 2020 6:35 pm

Yes, start by posting the code and error you're getting (use the code tags in the formatting bar, please).

Dave

dastels
 
Posts: 3819
Joined: Tue Oct 20, 2015 3:22 pm

Re: Need help sending analog voltage input to IO dashboard

by bigjoncop on Thu Mar 05, 2020 12:37 am

okay I was finally able to get the sketch to successfully upload. in serial monitor I am seeing the input voltage on the analog pin of the Arduino being displayed rapidly. so the sketch is reading the analog input and displaying it in the serial monitor.

I have my username and key entered correctly in config.h and ssId and password.

but on my Adafruit IO dashboard I'm not receiving any data. I've tried using a gauge, text, and stream none of them are displaying any information. they are just displaying the last value that Adafruit IO received when I originally ran the stock sample sketch. and just to verify that everything was working correctly I reran a stock sample sketch and I receive the information on my dashboard like normal. So it must be something in my sketch that's not right. below is my sketch.

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"

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




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

// THIS IS MY CUSTOM SKETCH... I USED A EXAMPLE SKETCH AND MODIFIED IT WITH MY CODE

    // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);

}

bigjoncop
 
Posts: 4
Joined: Wed Mar 04, 2020 7:01 am

Re: Need help sending analog voltage input to IO dashboard

by kcl1s on Thu Mar 05, 2020 8:15 am

You need to save your voltage value to your feed. Something like this after you read the voltage should work. analog->save(voltage); Don't forget to configure your dashboard to read the range of values you are sending.

Make sure you add at least a 1000 ms delay in your loop as you are limited on the number of feeds you can send per minute. They will suspend your account if you send too many.

Fellow hobbyist
Keith

kcl1s
 
Posts: 1511
Joined: Tue Aug 30, 2016 12:06 pm

Re: Need help sending analog voltage input to IO dashboard

by bigjoncop on Fri Mar 06, 2020 9:30 am

thank you that did it!!!

'm especially glad you told me about putting the delay in the sketch oh, it took me a few tries but eventually I stopped getting banned LOL. the sketch below is working and I am getting my analog zero pin data on my Adafruit dashboard. now I need to replicate that six more times so I can read pins A0 through A6....

I've tried for hours on hours to make that happen and no matter what I do the first air that I get is A1 is Undeclared. and I'm sure that's just the first of many many errors to come. I've use the find command in Arduino IDE and searched for A0 to see where it's declared at and how it's written and there is no other lines of A0 besides where its mentioned in my sketch below so I don't understand where else that it has to be declared at. I'm using a wemos D1 R1 with tons of analog inputs so the board has A1 pin.

if somebody could kindly just show me please how to add another analog input to send to my dashboard. I'm assuming it's basically just replicating the below code with a couple of added lines. as I mentioned earlier I'm Hardware guy I do not have patience at all for this kind of coding and I've been doing my best pulling my hair out just to get this far. I need to get my project moving along and I'm at wits end

I've also added my best guess and how to replicate my working sketch to add another analog input I'm sure it's completely wrong but again I can't get anywhere because it's saying A1 is not declared. please show me the solution please for the love of God, LOL

thanks again for all your help. Below is the working code. I only posted the modified section of the entire Adafruit sketch.

Code: Select all | TOGGLE FULL SIZE

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

    // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
 
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
 
  // print out the value you read:
  Serial.println(voltage);
analog->save(voltage);
delay(5000);

}


this is my best guess on how to add another analog input to the above sketch.

Code: Select all | TOGGLE FULL SIZE
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();

    // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
   int sensorValue2 = analogRead(A1);

  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
    float voltage = sensorValue2 * (5.0 / 1023.0);

  // print out the value you read:
  Serial.println(voltage);
analog->save(voltage);
delay(5000);// print out the value you read:
 
 Serial.println(voltage);
analog->save(voltage);
delay(5000);



}

bigjoncop
 
Posts: 4
Joined: Wed Mar 04, 2020 7:01 am

Re: Need help sending analog voltage input to IO dashboard

by kcl1s on Fri Mar 06, 2020 12:47 pm

This page says the Wemos D1 R1 only has 1 analog input. That is all the esp8266 has.

Keith

kcl1s
 
Posts: 1511
Joined: Tue Aug 30, 2016 12:06 pm

Please be positive and constructive with your questions and comments.