Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to I2C returning Serial #22

Closed
runfastman opened this issue Dec 22, 2020 · 10 comments
Closed

Change to I2C returning Serial #22

runfastman opened this issue Dec 22, 2020 · 10 comments

Comments

@runfastman
Copy link

I make a call in the beginning of the code to change to I2C but it always returns "Serial" but no error with the SetCommand. Do I need a parameter with the SET_I2C_MODE command?

Using Example code

void setup()
{
Serial.begin(115200); // Intialize terminal serial port
delay(20); // Give port time to initalize
printf_begin(); // Initialize printf.
printf("\r\nTFMPlus Library Example - 18JUN2020\r\n"); // say 'hello'

mySerial.begin(115200);  // Initialize TFMPLus device serial port.
delay(20);               // Give port time to initalize
tfmP.begin( &mySerial);   // Initialize device library object and...
                         // pass device serial port to the object.


// - - - - - - - - - - - - - - - - - - - - - - - -
printf( "SET_Mode: ");//SET_I2C_MODE, SET_SERIAL_MODE
if( tfmP.sendCommand(SET_I2C_MODE , 0))
{
    tfmP.printReply();
}
else 
{
  printf( "Failed: ");
  tfmP.printReply();
}

//.....

Output

SET_Mode: Status: SERIAL
00 00 00 00 00 00 00 00

@budryerson
Copy link
Owner

I'm sorry for the delay. You've probably figured it out by this time.
But will you please send me all your code so I can duplicate your problem?
Thanks,
Bud

@runfastman
Copy link
Author

runfastman commented Jan 1, 2021 via email

@budryerson
Copy link
Owner

There was no attachment with your last message.
Please send me your entire sketch ("all your code") so that I can duplicate your problem.
You may send the archive to my email bud@budryerson.com
Please include images of your setup and cabling, if you think that will be helpful.
Thanks,
Bud

@budryerson
Copy link
Owner

  1. You listed only two lines of output:
    SET_Mode: Status: SERIAL
    00 00 00 00 00 00 00 00
    Is that it? Only two lines? No "Hello"?
    Something like:
    TFMPlus Library Example - 18JUN2020

  2. Your Software Serial assignment of Pins 0 & 1
    SoftwareSerial mySerial( 0, 1);
    appears to use the same pins as the hardware serial port.
    Are you sure about those pin assignments?
    Which Arduino board (and revision) are you using?

  3. Is the Arduino working? Is the sensor working?
    Is the Arduino working okay with the sensor in Serial mode?

We'll fix this.

Bud

@runfastman
Copy link
Author

runfastman commented Jan 2, 2021 via email

@budryerson
Copy link
Owner

  1. I apologize for any confusion. Your [images] are not showing up here. Please save your output into a text file and attach or send me the file.

  2. The D0 & D1 pins on the Nano V3.0 Module ATmega328P 5V 16MHz CH340G are the hardware serial lines that you use to program and communicate with the Nano from your IDE (running on your PC). The Nano has an onboard USB to TTL converter (CH340G) that requires the use of these pins. You cannot use these same pins to communicate with your TFMini-Plus. That's why we use the Software Serial library - because the ATmega328P does not have a second hardware serial port. I believe that pins 9 & 10 will work for that purpose (11 & 12 are for the SPI interface) ; but please check the Software Serial documentation for your particular board.

    You say that your Nano and your TFMini-Plus are working together just fine in Serial Mode. I don't see how that is possible, so I must really be misunderstanding something. Again, please send me a text file of your output from running the example sketch in the Serial Mode. Pictures of your wiring would be helpful, too.

  3. You are correct that the I2C Mode is the way to go. It will allow you to use more than one TFMini-Plus on the same bus.

Bud Ryerson
San Francisco

@runfastman
Copy link
Author

runfastman commented Jan 2, 2021 via email

@budryerson
Copy link
Owner

Your images are still not showing.

You wrote that, "the sensor is working and giving me the correct distance with serial." So I asked to see the output from TFMP_example.ino, the Serial Mode example sketch, running correctly. I don't see that. In the output you show above, every command has failed.

You wrote, "I do have to unplug the tx/rx wires to flash but then I plug back in and hit the rest button and monitor the output."
Why are you plugging and unplugging wires? Which "tx/rx wires" are you talking about? How do you "monitor the the output?"

I get the uneasy feeling that you are still confusing hardware and software serial ports. The hardware serial port is for programming and monitoring ONLY. The Software Serial port is for communicating with the Lidar. Am I wrong?

Please let me know.

Bud

@runfastman
Copy link
Author

runfastman commented Jan 3, 2021 via email

@budryerson
Copy link
Owner

Please understand that the Lidar device communicates with the Arduino - and the Arduino then turns around and communicates with the user (you). This requires two independent data channels. The USB cable connects the Arduino with your computer. It uses the D0 & D1 (TX/RX) pins. You cannot EVER use those to connect to the Lidar. You must use the Software Serial pins. BUT As soon as you send a SET_I2C_MODE command to the Lidar, that device can no longer communicate in serial mode. So DO NOT send any commands to change the communication mode until after we've got everything working in serial mode. Okay?
I am still not getting your files or images. Please contact me further by email at:
bud-at-budryerson-dot-com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants