The depth control.
That was the biggest challenge so far. It did not want to cooperate; it ignored me for hours and hours. There are times when I appreciate silence, but this wasn't one of those moments.
Eventually, I managed to make it communicate with me in voltages. That was strange; normally these things communicate in Amperes, but hey, never look a gift horse in the mouth.
After I found a library that worked the below code will let it communicate:
Imagine the pressure sensor as a "communication puzzle." It sends information bit by bit, like solving a jigsaw puzzle one piece at a time. Each piece (bit) is a tiny part of the whole picture (data).
The expresion "uint32_t sread(int p)" in code, is like a special tool for solving this puzzle. It does the following:
The sensor is able to sence the depth in mm so its pretty darn accurate, maybe too accurate, but if so I can make it work with averages over a certain time.
I'm not out of the ballpark yet, I have to use this data to compare signals sent by the receiver whith the actual valuses measured by the sensor and then sent a signal to theFwdPlane servo and toss a PID on top of it.
Have a nice one,
Bart
That was the biggest challenge so far. It did not want to cooperate; it ignored me for hours and hours. There are times when I appreciate silence, but this wasn't one of those moments.
Eventually, I managed to make it communicate with me in voltages. That was strange; normally these things communicate in Amperes, but hey, never look a gift horse in the mouth.
After I found a library that worked the below code will let it communicate:
uint32_t sread(int p)
{
uint32_t rval=0;
int x=0;
for(x=0;x<p;x++){
digitalWrite(sck,HIGH);
delayMicroseconds(10);
if(x<24){
rval <<= 1;
rval |= (digitalRead(din)?1:0);
}
digitalWrite(sck,LOW);
delayMicroseconds(10);
}
return rval;
}
{
uint32_t rval=0;
int x=0;
for(x=0;x<p;x++){
digitalWrite(sck,HIGH);
delayMicroseconds(10);
if(x<24){
rval <<= 1;
rval |= (digitalRead(din)?1:0);
}
digitalWrite(sck,LOW);
delayMicroseconds(10);
}
return rval;
}
Imagine the pressure sensor as a "communication puzzle." It sends information bit by bit, like solving a jigsaw puzzle one piece at a time. Each piece (bit) is a tiny part of the whole picture (data).
The expresion "uint32_t sread(int p)" in code, is like a special tool for solving this puzzle. It does the following:
- It starts by getting ready to receive a puzzle piece by making a signal (like a "let's start" sign).
- It waits a short moment to make sure everything is ready.
- It looks at the puzzle piece (the bit) and decides where it fits in the puzzle (called a rval variable).
- It then asks for the next puzzle piece (bit) and fits it in.
- This process continues for all the pieces (bits) of the puzzle.
- Finally, it assembles all the pieces (bits) into a complete picture (called the rval value).
The sensor is able to sence the depth in mm so its pretty darn accurate, maybe too accurate, but if so I can make it work with averages over a certain time.
I'm not out of the ballpark yet, I have to use this data to compare signals sent by the receiver whith the actual valuses measured by the sensor and then sent a signal to theFwdPlane servo and toss a PID on top of it.
Have a nice one,
Bart
Comment