yes it does. the finished stuff will have three units. Ardunino nano v3 , RS485 ttl to rs485, OLED 128x64. the sensor which has VCC gnd, A B & are connected to RS485.
i have some questions and thanks for visiting.
layout of prog.
#define RE 8
#define DE 7
//const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
const byte nitro[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
byte values[11];
SoftwareSerial mod(2,3);
void setup() {
Serial.begin(9600);
mod.begin(9600);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
display initializin code here
void loop() {
byte val1,val2,val3;
val1 = nitrogen();
delay(250);
val2 = phosphorous();
delay(250);
val3 = potassium();
delay(250);
some serial print codes
some display print codes
byte nitrogen(){
digitalWrite(DE,HIGH);
digitalWrite(RE,HIGH);
delay(10);
if(mod.write(nitro,sizeof(nitro))==8){
digitalWrite(DE,LOW);
digitalWrite(RE,LOW);
// When we send the inquiry frame to the NPK sensor, then it replies with the
response frame
// now we will read the response frame, and store the values in the
values[] arrary, we will be using a for loop.
for(byte i=0;i<7;i++){
//Serial.print(mod.read(),HEX);
values[i] = mod.read();
Serial.print(values[i],HEX);
}
Serial.println();
}
return values[4];
}
and another bite for phosphorus and yet another one for potassium. and that's all the code is. then these 3 functions store their values in 3 different variables for display.
my questions are.
1.
if(mod.write(nitro,sizeof(nitro))==8){
does the above code imply, >> if the returning values from sensor are of length 8 bit then do something.
2.
for(byte i=0;i<7;i++){
//Serial.print(mod.read(),HEX);
values[i] = mod.read();
Serial.print(values[i],HEX);
}
how many times the loops will repeat. is it 8. it appears to me it exits the loop before 7th round.
he mentioned the response value will be stored in values[] array. there are two values arrays. values[11] (on the top) & values*.*
so what is the usage for values[11].
since you mentioned ,HEX will be in hex format. is the serial.print printing in hex values. and could you explain how this value is displayed on OLED. is it fed to Arduino, and the conversion takes place inside. or how would it be.
and why do we loop. cant' we feed the incoming value in just one go.
"return values[4]; // returns the Nitrogen value only, which is stored at location 4 in the array" does it mean it is the result of the function byte nitrogen for display.
i reckon you have given a better expression for values but its almost same as Ru!!ch. i am still trying to figure out 