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

compilation error with hardware serial #2

Closed
virgafox opened this issue Dec 1, 2015 · 11 comments
Closed

compilation error with hardware serial #2

virgafox opened this issue Dec 1, 2015 · 11 comments

Comments

@virgafox
Copy link

virgafox commented Dec 1, 2015

Hi,

I'm trying to use your library with an Adafruit Bluefruit LE Micro, which is very similar to an Arduino Micro. It has a usb serial interface (Serial) and an Hardware UART serial on pins 0,1 (Serial1). I'm trying to compile the simple_measurement example without changing anything, (it already declares Serial1 as the interface for communication with the ut390b), but I get this error on compilation:

In file included from /Users/virgafox/Documents/Arduino/libraries/UT390B_Arduino_Library-master/examples/Simple_Measurement/Simple_Measurement.ino:5:0:
/Users/virgafox/Documents/Arduino/libraries/UT390B_Arduino_Library-master/UT390B.h:18:37: error: could not convert 'Serial' from 'Serial_' to 'HardwareSerial&'
     UT390B(HardwareSerial &serial = Serial) : serial(&serial) {
                                     ^
exit status 1

I'm sure it is an hardware serial, how can I solve this? Thank you

@ernestum
Copy link
Owner

ernestum commented Dec 2, 2015

Hi, I just commited a new branch with a templated version of the library. This allows you to inject any Class to be used as the "Serial" class.
https://github.com/erniejunior/UT390B_Arduino_Library/tree/templated_version

I adapted the simple_measurement example so it compiles on my side. Maybe you have to specify a different type in . You could try oder <Serial_>.

Did this help?

@virgafox
Copy link
Author

virgafox commented Dec 2, 2015

Hi,

thank you! it now compiles and I can load it on my board. I've loaded the simple_measurement and it compiled without changing anything! Now the board correctly triggers the measurement on the ut390b in loop, on the lcd i can see the measurements, but on the serial monitor I always get this:

The distance is -1 mm
The distance is -1 mm
The distance is -1 mm
The distance is -1 mm

Another strange thing is that it continues printing also with the ut390b switched off.
Any suggestions? Thanks a lot!

@virgafox
Copy link
Author

virgafox commented Dec 2, 2015

Another thing, my board works at 3.3V. For the communication from ut390 to arduino it should not be a problem, because the 2.7V TX goes inside a 3.3V RX. For the communication from arduino to ut390b I'm still using a voltage divider with equal 10kohm resistor, so the output may be a little too low, but the measurements are triggered, so I think that it should not be a problem.. Thanks again!

@ernestum
Copy link
Owner

ernestum commented Dec 2, 2015

Hi,

the library returns -1 if it has problems parsing the answer from the ut390. There can be different ways in which the parsing fails: there can be unexpected characters or it can run into a timeout (when no new data arrives from the serial port). This explains why it keeps printing -1 even if the ut390 is switched off.
Unfortunately I can not test my code any more because I do not have the distance meter here with me. But I can give you the following hints for debugging:

  1. Check that there is actually any data arriving at your Arduino.
  2. Check that the data is arriving in the correct format (see here for a description of the format so you know what to expect.
  3. Looking at your repositories, you seem to have some prior programming experience, so I recommend to have a look into my library, especially the readMeasurement() method where the measurement is actually parsed (it is reasonably well documented). Try putting Serial.println() statements (with meaningful content) at the various places of the method where it returns -1. This way you can narrow down the cause for why the parsing fails. If you find a bug in my parsing routine feel free to fix it and send me a pull request :-)

@virgafox
Copy link
Author

virgafox commented Dec 2, 2015

Hi,
thank you very much for your support. In order to understand what is going on, I've loaded this simple sketch on the board:

void setup() {
  Serial.begin(9600);
  Serial1.begin(115200);
}

void loop() { 
  if (Serial1.available()) {
    Serial.write(Serial1.read());
  }
  if (Serial.available()) {
    Serial1.write(Serial.read());
  }
}

When I send the command *004040#, the ut390b takes the measurement, but the serial monitor prints this (two executions).

!���sY��:�1Nb ��sY�� ��9L�
!Tk�� L�,���e[�=L�
!��s��1�,W�p�W� C�*�0��0�0�81&�

!���sY��:�8b P+�eiK�40Ӫ,C�
Tk�:�8Li��tY��=L�
!��s��1�,W�p��0j��*�0��0�0�8L&�

So I'm getting the data, but probably not in the right format :) I'l try to investigate on this...

@ernestum
Copy link
Owner

ernestum commented Dec 2, 2015

OK now I see a lot of question marks on black background which indicate encoding issues:
screenshot - 12022015 - 11 17 32 pm
Is this what you actually read from the Arduino or is this our browsers screwing with us?

Anyway, this looks like the data coming from the laser distance meter is total gibberish. That might be a bad connection causing false edges. Try wiggling your cables and see if you receive more random data. Your reasoning with the voltages up there seems to be good, but I am by no means an electrical engineer.

Also make sure you connected RX on the Arduino to the TX on the UT390B.
Check your battery. Try to write to your hardware serial using software serial (create a loop) to see if your hardware serial might be broken.

That is all I came up with right now ... I am sorry you have such a bad time with your toy.

@virgafox
Copy link
Author

virgafox commented Dec 3, 2015

Hi,
it is not the browser, it is actually what I see on the serial monitor. I'll do the checks you suggested. thanks again and sorry for the disturb!

@virgafox
Copy link
Author

virgafox commented Dec 6, 2015

Here I am again XD please don't hate me.
I've checked all the solderings and they seem ok. I've also tried executing the code using a very short cable directly touching the pad, but same result. TX and RX connections seem ok, also because I can trigger the measurement, and I get "something" back after it. I've done the check looping with a software serial, and the interface is working good. What I see that is a little strange is that the "gibberish" has some "regular" patterns. If the problem is linked with the connection, I think that I should receive something more random, so maybe it is a "parsing" issue. I'm not very skilled in C, can I ask you a way to add to your library some "debug" prints that output the raw data from the laser?
Thanks a lot

@ernestum
Copy link
Owner

ernestum commented Dec 6, 2015

I did just add lots of debug outs to that templated_version branch. Every line starting with ">" contains raw data that comes into the Serial port. All the other lines are just "comments" to understand what is going on in the parser.

To for debugging you could also set up your loop again and just fake the data that you would expect to come from the UT390B. E.g. a message like *0006400000065305# should be parsed as 653mm distance.

Again I could only check that the code compiles, not that it runs!

You also owe me now to tell me what project you are using my library for. I am always happy if other people can make use of my work!

@virgafox
Copy link
Author

virgafox commented Dec 9, 2015

Hi!
finally I managed to get the whole thing working by switching to a standard Arduino Mega. It seems that the 3.3V serial is not usable for this! I'm using your library in a little project where two robots need to keep a specific distance between each other! thanks a lot for your help! :)

@virgafox virgafox closed this as completed Dec 9, 2015
@ernestum
Copy link
Owner

ernestum commented Dec 9, 2015

That is great! Have fun then.

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