stoduk / PingSerial

Arduino library for using serial enabled ultrasonic distance modules (eg. US-100)
MIT License
16 stars 9 forks source link

Hello Stoduk #10

Closed Stanleydu95 closed 4 years ago

Stanleydu95 commented 4 years ago

Hello Stoduk

I m new from Github . I have question about your PingSerial.

Actually we use HC SR04 , but we have a lot of mistake with this sensor. I want to change for US-100 in using serial Mode . I m new from Arduino Can I have your help ? Thanks in advance.

stoduk commented 4 years ago

What issue do you need help with?

On 20 Jan 2020, at 17:39, Stanleydu95 notifications@github.com wrote:

 Hello Stoduk

I m new from Github . I have question about your PingSerial.

Actually we use HC SR04 , but we have a lot of mistake with this sensor. I want to change for US-100 in using serial Mode . I m new from Arduino Can I have your help ? Thanks in advance.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Stanleydu95 commented 4 years ago

Its for me first time to use Arduino ( my model is mega2560 ) I don't code . I m newbee. In my project , they use HC SRO4 but in TRIGGER and ECHO . I want to use US-100 with Arduino and Raspberry for find thing in the box.

stoduk commented 4 years ago

I'm still not sure what you are after! :)

If you are so new to Arduino, then perhaps it would be worth your time working through some introductions - I imagine instructables.com will have plenty. You can probably also find a walk-through example of how to use HC-SR04 and perhaps even the US-100.

The US-100 is ultimately very simple, you just talk to it over a serial connection. This library wraps some of the less pleasant aspects of the interaction but your first step needs to be confirming you can get the US-100 to talk without the library.

Hopefully that gives you something to go on. If you haven't go any questions relating to this library then I'll close this bug report in a day or two.

Stanleydu95 commented 4 years ago

Hello Stoduk

I want just to measure Arduino Mega2560 with US-100 in serial.

But when I use your library and your code I have issue .

When I take your example for PingSerialDistance :

I have issue :

Arduino : 1.8.10 (Mac OS X), Carte : "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from /Users/toto/Desktop/PingSerial-master/examples/PingSerialExample/PingSerialDistance/PingSerialDistance.ino:8:0: /Users/toto/Documents/Arduino/libraries/PingSerial-master/PingSerial.h:131:8: warning: extra tokens at end of #endif directive [-Wendif-labels]

endif __PINGSERIAL_H__

    ^~~~~~~~~~~~~~~~

In file included from /Users/toto/Documents/Arduino/libraries/PingSerial-master/PingSerial.cpp:7:0: /Users/toto/Documents/Arduino/libraries/PingSerial-master/PingSerial.h:131:8: warning: extra tokens at end of #endif directive [-Wendif-labels]

endif __PINGSERIAL_H__

    ^~~~~~~~~~~~~~~~

Le croquis utilise 5172 octets (2%) de l'espace de stockage de programmes. Le maximum est de 253952 octets. Les variables globales utilisent 357 octets (4%) de mémoire dynamique, ce qui laisse 7835 octets pour les variables locales. Le maximum est de 8192 octets. avrdude: stk500v2_ReceiveMessage(): timeout avrdude: stk500v2_ReceiveMessage(): timeout avrdude: stk500v2_ReceiveMessage(): timeout avrdude: stk500v2_ReceiveMessage(): timeout avrdude: stk500v2_ReceiveMessage(): timeout avrdude: stk500v2_ReceiveMessage(): timeout avrdude: stk500v2_getsync(): timeout communicating with programmer Une erreur est survenue lors du transfert du croquis

Ce rapport pourrait être plus détaillé avec l'option "Afficher les résultats détaillés de la compilation" activée dans Fichier -> Préférences.

Stanleydu95 commented 4 years ago

include

include

// Here US-100 is connected to Serial, so we have debugging on a SoftwareSerial port (eg. connected to Bluetooth module or TTL-USB adaptor). PingSerial us100(Serial, 650, 1200); // Valid measurements are 650-1200mm SoftwareSerial SerialDbg(1, 0); // SoftwareSerial for debugging from this script (not

bool ping_enabled = FALSE; unsigned int pingSpeed = 100; // How frequently are we going to send out a ping (in milliseconds). 50ms would be 20 times a second. unsigned long pingTimer = 0; // Holds the next ping time.

void setup() { us100.begin(); SerialDbg.begin(9600); }

void loop() { byte data_available; unsigned int current_height = 0;

/*

Stanleydu95 commented 4 years ago

I use your code now and I have this mistake

Stanleydu95 commented 4 years ago

In file included from /Users/toto/Desktop/PingSerial-master/examples/PingSerialExample/PingSerialDistance/PingSerialDistance.ino:3:0: /Users/toto/Documents/Arduino/libraries/PingSerial-master/PingSerial.h:131:8: warning: extra tokens at end of #endif directive [-Wendif-labels]

endif __PINGSERIAL_H__

    ^~~~~~~~~~~~~~~~

Le croquis utilise 5172 octets (2%) de l'espace de stockage de programmes. Le maximum est de 253952 octets. Les variables globales utilisent 357 octets (4%) de mémoire dynamique, ce qui laisse 7835 octets pour les variables locales. Le maximum est de 8192 octets.

Stanleydu95 commented 4 years ago

So I use this code :

include

const int US100_TX = 2; const int US100_RX = 3;

// Instancia nuevo canal serie SoftwareSerial puertoUS100(US100_RX, US100_TX);

unsigned int MSByteDist = 0; unsigned int LSByteDist = 0; unsigned int mmDist = 0; int temp = 0;

void setup() { Serial.begin(9600); puertoUS100.begin(9600); }

void loop() {

puertoUS100.flush(); // limpia el buffer del puerto serie
puertoUS100.write(0x55); // orden de medición de distancia

delay(500);

if(puertoUS100.available() >= 2) // comprueba la recepción de 2 bytes
{
    MSByteDist = puertoUS100.read(); // lectura de ambos bytes
    LSByteDist  = puertoUS100.read();
    mmDist  = MSByteDist * 256 + LSByteDist; // distancia
    if((mmDist > 1) && (mmDist < 10000)) // comprobación de la distancia dentro de rango
    {
        Serial.print("Distancia: ");
        Serial.print(mmDist, DEC);
        Serial.println(" mm");
    }
}

puertoUS100.flush(); // limpia el buffer del puerto serie
puertoUS100.write(0x50); // orden de medición de distancia

delay(500);
if(puertoUS100.available() >= 1) // comprueba la recepción de 1 byte
{
    temp = puertoUS100.read(); // lectura del byte
    if((temp > 1) && (temp < 130)) // comprobación de rango válido
    {
        temp -= 45; // corrige offset de 45º
        Serial.print("Temperatura: ");
        Serial.print(temp, DEC);
        Serial.println(" ºC.");
    }
}

delay(500);

}

Stanleydu95 commented 4 years ago

But in monitor or tracer I don't have anything. Why ? thanks in advance for your help

stoduk commented 4 years ago

The errors relating to "#endif PINGSERIAL_H" are actually just warnings, so can be ignored - they aren't relevant. The problem here is (translating your output Fr->En) that your Arduino software can't talk to your board - "Une erreur est survenue lors du transfert du croquis".

I suspect something is wrong with your setup, or perhaps your Arduino just wasn't plugged in. Can you upload one of the basic Ardunio Example sketches - blink is a trivial one so worth testing with.

You've copied coped from Arduibots and said it didn't work. Did it successfully upload to your Arduino? If that isn't working then maybe your code never uploaded, or maybe your connections between the Arduino and US-100 are wrong, or maybe the jumper on the US-100 is set wrong (serial vs. echo/response).

Hopefully that helps you but I feel like you are trying to run before you can walk! Try to get the blink example script uploaded to your Arduino, then try to get the Arduibots code to work (which is a rough-and-ready version I based mine on). Once those both work then hopefully my code should just work - or at least the problems might be in my code rather than elsewhere.

HTH

Stanleydu95 commented 4 years ago

Thanks you for your understanding. I run I sure but we did a project with HC SR04 . Its turns out that the sensors are less reliable compared to the US-100 in serial.

I understand that for mode serial , I can use PIN TX and RX from Arduino ( Pin 0 and 1)

But when I upload the code (when I put pin before upload ) I have mistake : (avrdude: stk500v2_ReceiveMessage(): timeout)

I find , when I don't put pin before upload and in first I upload the code . This is functionnaly.

But When I use jumber for US-100 I don't see a bad info for measure.

In fact I succeeded only to user US-100 In mode ECHO/Response but not Serial.

And my goal is to make the test for captation in mode serial.

I try also this code from Arduibots and this circuit but me , I have only Elegoo Mega2560 and not Arduino Nano V3

Thanks in advance Stoduk and sorry for my English

Stanleydu95 commented 4 years ago

And Blink is OK ;-)

stoduk commented 4 years ago

Some Arduinos (eg. Leonardo) have USB capabilities built in to the chip; many Arduinos however have a secondary processor or dedicated IC to provide USB:TTL conversion which will be connected to the first TTL serial port (Rx0/Tx0). This USB:TTL adaptor is used both for programming (assuming you aren't using ICSP, which you almost certainly aren't) and for using the serial monitor to talk/listen to the Arduino.

Unless you are really sure of what you are doing, do not connect anything to the first serial port as it will likely break programming and serial monitor functionality. You've got a meatier Arduino with four hardware serial ports (also known as UARTs) so connect the US-100 to eg. Serial1 and leave Serial (which should really be called Serial0, but isn't) for programming/serial monitor.

So - change where your US-100 is connected, modify the example code to use a different UART and things will likely then Just Work. See https://store.arduino.cc/arduino-mega-2560-rev3 for details of which pins to use.

Stanleydu95 commented 4 years ago

It Works . When I use Serial1 , I m not issue. Thanks you so much Stoduk . Now I take time for learn Arduino. You have seen different between HC SR04 and US-100 in serial Mode ??

Stanleydu95 commented 4 years ago

I use your example PingSerial with temperature.

stoduk commented 4 years ago

Glad it is all sorted, quite a simple problem in the end!