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

sendCommand() not working with Arduino MKR GSM 1400 #34

Closed
ibrcic opened this issue May 26, 2021 · 5 comments
Closed

sendCommand() not working with Arduino MKR GSM 1400 #34

ibrcic opened this issue May 26, 2021 · 5 comments

Comments

@ibrcic
Copy link

ibrcic commented May 26, 2021

Hello,

I am using the library with TFMini Plus and Arduino MKR GSM 1400 board.
I connected the sensor to TX and SX serial ports on my board. I can get the distance data without a problem as that is working as expected.

What I do have problem with is sending ANY command to the sensor itself. The execution just halts and nothing is returned by sendCommand() function. Here is an example code that does not work (I want to check firmware version, but ultimately want to change to I2C as I'll connect multiple sensors).

Here is the code example (I'm using Serial.print() as printf is not working)

#include <TFMPlus.h>
#include "printf.h"

TFMPlus tfmP;
void setup()
{

  Serial.begin(9600);
  while (!Serial);
  delay(20);

  Serial1.begin(115200);
  delay(20);               // Give port time to initalize
  tfmP.begin( &Serial1);
  
  delay(500);

  if (tfmP.sendCommand(OBTAIN_FIRMWARE_VERSION, 0))
  {
    Serial.println("Printing firmware version:");
  }
  else
  {
    Serial.println("Error printing version");
    tfmP.printReply();
  }
}


void loop()
{

}

When I run this, nothing is printed to the serial monitor, the execution apparently stops in tfmP.sendCommand(OBTAIN_FIRMWARE_VERSION, 0) part of the code.

@budryerson
Copy link
Owner

Hello,

Thank you for the sketch. With no output at all, the execution must stop somewhere before the first Serial.println() instruction. Could you add a Serial.println("Hi there!"); after Serial.begin() and another after Serial1.begin()?

Although I am not familiar with the Arduino MKR GSM 1400, I understand that MKR boards address pins D13 and D14 as Serial1.
Would you be kind enough to send me a picture of your setup?

Thanks,

Bud Ryerson
San Francisco

@ibrcic
Copy link
Author

ibrcic commented May 27, 2021

Hello,

I tried adding that and it prints without problems, so it really seems that execution stops at sendCommand().

image

Yes, Serial1 should be at D13 and D14, and that is how I connected it, here is the photo of my setup:

189799267_1409582969403840_9180174187597714258_n

@budryerson
Copy link
Owner

Great! Thanks.
I tried to make this library as bullet-proof as I could imagine - so that it would return something and not just hang. I'm really sorry about the situation. I want to help, and I want to understand what's going on.

I am mystified. You got past Serial1.begin(); but that doesn't return much information. Now please show me how you get distance data. Maybe after delay(500); you could add some code like this?

int16_t tfDist = 0;
tfmP.getData( tfDist);
Serial.println( tfDist);

And if that doesn't work, try something more basic, like:

if( Serial1.available()) Serial.println( Serial1.read());
else Serial.println( "Serial1 data not available.");

I hope did that right. I'm not at the lab. Please Let me know what happens.

Thanks,
Bud

@ibrcic
Copy link
Author

ibrcic commented May 28, 2021

Hi,

I managed to resolve my issue, although not directly. First I used the provided GUI to change the communication mode to I2C (because that's what I'll be using for this project). After changing the mode, sending commands still didn't work. However, when I powered my Arduino from bench power supply in addition to connecting it to the PC via USB, everything started behaving normally.

I don't know if power was the culprit with serial communication also, but currently everything is working as expected with I2C version of this library, so this issue can be closed.

Thank you for your help!

@budryerson
Copy link
Owner

That sounds right, and it's good information for the next person.
Thanks.

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