Profile cover photo
Profile photo
Tony Harding
162 followers -
Sauron
Sauron

162 followers
About
Tony's interests
View all
Tony's posts

Post has attachment

I'm having a bit of a problem with the IDE compiling the following code, in which it has an issue with the "arrayarray" declarations. Namely the line that reads:

voltage = avergearray(pHArray, ArrayLenth)5.0/1024

I'm including the file here, but I'm also sharing the code in a Google Docs file in case it's easier (although I know it's not the optimal way to share code). But in there I've bolded the troublesome section.

https://docs.google.com/document/d/1HdSlOuaLFxXo3anqsCEpjZ8ya9ftAeDoyR6osEJAeyM/edit?usp=sharing

Any help is much appreciated.

#include "HX711.h"
#define trigPin 13
#define echoPin 12
#define SensorPin A15
#define Offset 0.00 //deviation compensate
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth 40 //times of collection
int pHArray[ArrayLenth]; //Store the average value of the sensor feedback
int pHArrayIndex=0;
float pHValue;
float voltage;
HX711 scale1;
HX711 scale2;
HX711 scale3;
HX711 scale4;

void setup() {
Serial.begin(115200);
Serial.println("Initializing the scale");
scale1.begin(A1, A0);
scale2.begin(A4, A0);
scale3.begin(A8, A0);
scale4.begin(A10, A0);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

Serial.println("Before setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale1.read()); // print a raw reading from the ADC
Serial.println(scale2.read());
Serial.println(scale3.read());
Serial.println(scale4.read());

Serial.print("read average: \t\t");
Serial.println(scale1.read_average(20)); // print the average of 20 readings from the ADC
Serial.println(scale2.read_average(20));
Serial.println(scale3.read_average(20));
Serial.println(scale4.read_average(20));

Serial.print("get value: \t\t");
Serial.println(scale1.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
Serial.println(scale2.get_value(5));
Serial.println(scale3.get_value(5));
Serial.println(scale4.get_value(5));

Serial.print("get units: \t\t");
Serial.println(scale1.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
Serial.println(scale2.get_units(5), 1);
Serial.println(scale3.get_units(5), 1);
Serial.println(scale4.get_units(5), 1);
// by the SCALE parameter (not set yet)

scale1.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details
scale1.tare(); // reset the scale to 0
scale2.set_scale(2280.f);
scale2.tare();
scale3.set_scale(2280.f);
scale3.tare();
scale4.set_scale(2280.f);
scale4.tare();

Serial.println("After setting up the scale:");

Serial.print("read: \t\t");
Serial.println(scale1.read()); // print a raw reading from the ADC
Serial.println(scale2.read());
Serial.println(scale3.read());
Serial.println(scale4.read());

Serial.print("read average: \t\t");
Serial.println(scale1.read_average(20)); // print the average of 20 readings from the ADC
Serial.println(scale2.read_average(20));
Serial.println(scale3.read_average(20));
Serial.println(scale4.read_average(20));

Serial.print("get value: \t\t");
Serial.println(scale1.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
Serial.println(scale2.get_value(5));
Serial.println(scale3.get_value(5));
Serial.println(scale4.get_value(5));

Serial.print("get units: \t\t");
Serial.println(scale1.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
Serial.println(scale2.get_units(5), 1);
Serial.println(scale3.get_units(5), 1);
Serial.println(scale4.get_units(5), 1);
// by the SCALE parameter set with set_scale

Serial.println("Readings:");
}

void loop() {
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;

static unsigned long samplingTime = millis();
static unsigned long printTime = millis();
//static float pHValue,voltage;
if(millis()-samplingTime > samplingInterval)
{
pHArray[pHArrayIndex++]=analogRead(SensorPin);
if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;
voltage = avergearray(pHArray, ArrayLenth)*5.0/1024;
pHValue = 3.5*voltage+Offset;
samplingTime=millis();
}
// if(millis() - printTime > printInterval) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
//{
// Serial.print("Voltage:");
// Serial.print(voltage,2);
// Serial.print(" pH value: ");
//Serial.println(pHValue,2);
// printTime=millis();
//}

double avergearray(int arr, int number){
int i;
int max,min;
double avg;
long amount=0;
if(number<=0){
Serial.println("Error number for the array to avraging!/n");
return 0;
}
if(number<5){ //less than 5, calculated directly statistics
for(i=0;i<number;i++){
amount+=arr[i];
}
avg = amount/number;
return avg;
}else{
if(arr[0]<arr[1]){
min = arr[0];max=arr[1];
}
else{
min=arr[1];max=arr[0];
}
for(i=2;i<number;i++){
if(arr[i]<min){
amount+=min; //arr<min
min=arr[i];
}else {
if(arr[i]>max){
amount+=max; //arr>max
max=arr[i];
}else{
amount+=arr[i]; //min<=arr<=max
}
}//if
}//for
avg = (double)amount/(number-2);
}//if
return avg;
}
// Serial.print("one reading1:\t");
//Serial.print(scale1.get_units(), 1);
// Serial.print("one reading2:\t");
// Serial.print(scale2.get_units(), 1);
// Serial.print("one reading3:\t");
//Serial.print(scale3.get_units(), 1);
// Serial.print("one reading4:\t");
// Serial.print(scale4.get_units(), 1);
// Serial.print("\t| average1:\t");
Serial.print(scale1.get_units(10), 1);
// Serial.print("\t| average2:\t");
Serial.print(",");
Serial.print(scale2.get_units(10), 1);
// Serial.print("\t| average3:\t");
Serial.print(",");
Serial.print(scale3.get_units(10), 1);
// Serial.print("\t| average4:\t");
Serial.print(",");
Serial.print(scale4.get_units(10), 1);
Serial.print(",");
Serial.print(pHValue,1);
Serial.print(",");
Serial.println(distance);
scale1.power_down();
scale2.power_down();
scale3.power_down();
scale4.power_down();
// put the ADC in sleep mode
delay(10000);
scale1.power_up();
scale2.power_up();
scale3.power_up();
scale4.power_up();
}




Post has attachment
I have a JavaScript question. We're trying to create a timer that takes an inputted value from the user and counts down from there.

I have the code I'm working with which is available as a public file on Google Docs
https://docs.google.com/document/d/1wxhVhFsdIS__tHiwPvrGZqsLX_MyaR895vcGXh-XBak/edit?usp=sharing

I know that Google Docs is not the BEST way to share code, however that's what I have right now to share the whole code.

The particular bit of interest here are the last 4 lines. WHERE THE X is, I would like to add a custom day field that's entered from a text box.

If you have another code that may work better, just let me know.

Thanks in advance.

Post has attachment
I have a JavaScript question. We're trying to create a timer that takes an inputted value from the user and counts down from there.

I have the code I'm working with which is available as a public file on Google Docs
https://docs.google.com/document/d/1wxhVhFsdIS__tHiwPvrGZqsLX_MyaR895vcGXh-XBak/edit?usp=sharing

I know that Google Docs is not the BEST way to share code, however that's what I have right now to share the whole code.

The particular bit of interest here are the last 4 lines. WHERE THE X is, I would like to add a custom day field that's entered from a text box.

If you have another code that may work better, just let me know.

Thanks in advance.

Post has attachment
I have a JavaScript question. We're trying to create a timer that takes an inputted value from the user and counts down from there.

I have the code I'm working with which is available as a public file on Google Docs
https://docs.google.com/document/d/1wxhVhFsdIS__tHiwPvrGZqsLX_MyaR895vcGXh-XBak/edit?usp=sharing

I know that Google Docs is not the BEST way to share code, however that's what I have right now to share the whole code.

The particular bit of interest here are the last 4 lines. WHERE THE X is, I would like to add a custom day field that's entered from a text box.

If you have another code that may work better, just let me know.

Thanks in advance.

Post has attachment
So, I was following the instructions on http://elinux.org/RPi-Cam-Web-Interface on how to get the Raspberry Pi Camera to work. I forgot to enable the RPi Cam from the settings and proceeded to do the update/dist-upgrade.

Now I'm trying to install the package and I get some errors. Does that mean that after now I enable the camera, that I have to do the update/dist-upgrade again?

Post has attachment

Post has attachment

Hi All,

I need to write a very simple program in Arduino that ONCE a pushbutton is enabled (regardless if it was set as an INPUT_PULLUP or just an INPUT) that it starts a timer for which it waits an X amount of milliseconds and writes a 0 to the output then turns on the output writing a 1 for another set of Y amount of milliseconds regardless if the button changes states in the meantime.

Basically, once the pushbutton is enabled, it waits, and then it actuates.

Any help on this?

Post has attachment
Hi all, simple question here, and I'm almost confident there's a very simple solution to this but:

I'm using the RPi-Cam-Web-Interface available at eLinux.org: http://elinux.org/RPi-Cam-Web-Interface

I've gone through the installation steps and everything works great when I try to access the interface while using the local IP of the Pi, however, when I try to access from a mobile device that's also connected to the LAN it doesn't want to access.

As far as I know, it's all reporting to port 80 which is the default html port.

Could this be a router issue or another adjustment I need to make anywhere else?

Wait while more posts are being loaded