Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Here isExample of sending analog inputs over ethernet shield
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Here isExample of sending analog inputs over ethernet shield

by malc on Fri Aug 22, 2008 9:47 am

// Arduino - Ethernet Shield example
//This sketch returns the six analog input values over the ethernet shield.
// Ten samples of each port are averaged before sending.
// The values are sent whenever the Ethernet Shield receives a character.
// If the character sent to the shield is a c, the six analog DAC COUNTS are returned as follows:
// c,823,815,811,756,697,657
// If the character sent is anything else, the six analog values are returned as millivolts as follows:
// s,3995,3986,3966,3565,3220,2989
// The first item in each string is the echoed back character that the user sent.
// (in this case it was 'c', or 's')
//
// To test this, use the following telnet command:
// telnet 192.168.1.113 10001 (substitute the IP address that your XPort is using)
// Hit a a key on your keyboard once telnet session connects to see values
//
// Before you run this, please get the basic test example working.
// Example is at: http://ladyada.net/make/eshield/test.html
// Malcolm Stitt 22-Aug-2008



#include "AFSoftSerial.h"

AFSoftSerial mySerial = AFSoftSerial(3, 2);

void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println("Ethernet Analog Responder Starting Up");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}

void loop()
{
char s;
float fval;
int i,port,val;
if (mySerial.available())
{
s= (char)mySerial.read();
Serial.print(s);
// run for each analog portfs
for(port=0;port<6;port++)
{
val=0;
// sample each input 10 times
for(i=0;i<10;i++) val+=analogRead(port);
// if typed character was c, return counts, else return millivolts
if(s=='c')
{
val=val/10; //divide by the number of samples to get avg DAC counts
}
else
{// Analog DAC has 1024 counts over 5 volts = 205 counts per volt
//convert to millivolts (1 volt = 205 counts, but we are dividing sum of 10 samples
// and converting to millivolts, so divide by 2.05 instead of 205
fval=val/2.05;
val=(int)fval;

}
mySerial.print(",");
mySerial.print(val);

}
mySerial.println("");
}
}

malc
 
Posts: 23
Joined: Wed Aug 06, 2008 4:53 pm

Please be positive and constructive with your questions and comments.