Skocz do zawartości

Problem z czujnikiem arduino nano


Pomocna odpowiedź

Napisano

Witam, potrzebuję obsłużyć taki czujnik : https://botland.com.pl/ultradzwiekowe-czujniki-odleglosci/8832-ultradzwiekowy-czujnik-odleglosci-urm07-750cm-uart-z-korekcja-temperaturowa.html na arduino nano. Wpisuje kod ze strony producenta ale nie działa, wyrzuca jakieś krzaki. Co moze być przyczyną? Taki czujnik da się w ogóle obsłużyć przez arduino nano?

kod:

*The circuit:
  RX is digital pin 10 (connect to TX of other device)
  TX is digital pin 11 (connect to RX of other device)*/
#include <SoftwareSerial.h>

#define header_H    0x55 //Header
#define header_L    0xAA //Header
#define device_Addr 0x11 //Address
#define data_Length 0x00 //Data length
#define get_Dis_CMD 0x02 //Command: Read Distance
#define checksum    (header_H+header_L+device_Addr+data_Length+get_Dis_CMD) //Checksum

SoftwareSerial NewSerial(10, 11);

unsigned char i = 0;
unsigned int  Distance = 0;
unsigned char Rx_DATA[8];
unsigned char CMD[6] = {
 header_H, header_L, device_Addr, data_Length, get_Dis_CMD, checksum
}; //Distance command package

void setup()
{
 NewSerial.begin(19200);  //Serial1: Ultrasonic Sensor Communication Serial Port, Buadrate: 19200
 Serial.begin(19200);   //Serial: USB Serial Data output, baudrate: 19200
}

void loop() {
 for (i = 0; i < 6; i++) {
   NewSerial.write(CMD[i]);
 }
 delay(150);  //Wait for the result
 i = 0;
 while (NewSerial.available()) { //Read the return data (Note: this demo is only for the reference, no data verification)
   Rx_DATA[i++] = (NewSerial.read());
 }
 Distance = ((Rx_DATA[5] << ? | Rx_DATA[6]); //Read the distance value
 Serial.print(Distance);               //print distance value
 Serial.println("cm");
}

Błąd:

C:\Users\admin\Documents\Arduino\Drzewo_CzujnikDuzyNowaBiblioteka\Drzewo_CzujnikDuzyNowaBiblioteka.ino:20:1: warning: narrowing conversion of '274' from 'int' to 'unsigned char' inside { } [-Wnarrowing]

}; //Distance command package

^

C:\Users\admin\Documents\Arduino\Drzewo_CzujnikDuzyNowaBiblioteka\Drzewo_CzujnikDuzyNowaBiblioteka.ino:20:1: warning: large integer implicitly truncated to unsigned type [-Woverflow]

29341390_762549500622538_1871814744_n.thumb.png.90afd393240eb07aa152ce6b553d8399.png

Bądź aktywny - zaloguj się lub utwórz konto!

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto w ~20 sekund!

Zarejestruj nowe konto, to proste!

Zarejestruj się »

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się »
×
×
  • Utwórz nowe...