try your GL041MT_Test to verify the sonar still works.
It works correctly.
Please refer to the picture.
I removed the startup print to serial, its the only extra line of code thats running. it should be line for line identical to what your example, as everything else is commented out
when you remove whats commented out its identical, thats why im confused as to why its not working
ok some searching and apparently arduino can get strange with commented out libraries. so i2c might be still causing issues even with it commented out.
here is a different version, this uses the hardware serial port rather than software serial so it can handle high speed serial input without causing problems for other IO, im sure i ran into this issue before when making a radar adapter where softserial and i2c compete for cpu time. this wasnt an issue for the other sonar as it only ran at 9600.
so for this version wire the sonar to the hardware TX RX pins on the arduino, it should blink the led if its working ok.
you need to close the serial connection from it as we are now using that port for the sonar, is the led blinking?
what board are you using specifically so i know what leds you have on it.
Use the Arduino Uno board,
The RX LED blinks very quickly.
is the L or TX led blinking or flickering? the rx flashing is a good sign that means the sonar is sending data.
I updated the code to add a small delay, i think im just turning off the led too fast.
did it stay on with the latest version ?
That video is similar to what we are doing, but that sonar uses trig echo not serial.
I have ordered one to work on.
i2c transmission part,
If you properly combine the GL041MT related codes,
It seems to work.
yes because they are not using serial, the problem we are having is the fast softserial cannot run at the same time as i2c, with 9600 that the other sonar works fine but at 115200 this sonar needs, the cpu just isnt fast enough, thatβs why we are having to use hardware serial.
do you have any other boards? something faster like a rp-2040, that wouldnt have the same issues as its more than fast enough to run i2c and softserial.
The board I have is
These are the Uno board and Nano board.
does the L led flash with the latest code?
yes, its been updated to add some delay to flash the led.
Hi @Peter_Kim, @geofrancis ! Did you manage to get the i2c data for autopilot ?
basically the 115200 speed is causing softserial to conflict with i2c, so we were working on connecting the sonar to the hardware serial port to get around that issue.
my next step was to take the working example and swap the hardware and softserial ports, this will let us run the hardware serial at 115200 and the softserial at 9600 for printing the values. we can use it to get the sonar working with hardware serial, once that is working we can add i2c then disable softserial.
#include <SoftwareSerial.h>
unsigned char buffer_RTT[4] = {0};
uint8_t CS;
#define COM 0x55
int Distance = 0;
SoftwareSerial mySerial(10, 11);
void setup() {
Serial.begin(115200);
mySerial.begin(9600);
}
void loop() {
Serial.write(COM);
delay(100);
if(Serial.available() > 0){
delay(4);
if(Serial.read() == 0xff){
buffer_RTT[0] = 0xff;
for (int i=1; i<4; i++){
buffer_RTT[i] = Serial.read();
}
CS = buffer_RTT[0] + buffer_RTT[1]+ buffer_RTT[2];
if(buffer_RTT[3] == CS) {
Distance = (buffer_RTT[1] << 8) + buffer_RTT[2];
mySerial.print("Distance:");
mySerial.print(Distance);
mySerial.println("mm");
}
}
}
}
Understood, thanks; Iβll keep an eye on the project. My sonar is still on the way.
I have one ordered too, will probably be here next weekend.