Liczba postów: 4
Liczba wątków: 1
Dołączył: Oct 2017
Reputacja:
0
Serdecznie witam,
Podłączyłem do Arduino Nano Every moduł XBee Pro. Jak wskazać podczas inicjacji tego modułu, że pracuje on na Serial1 a nie Serial?
Dziękuję za pomoc.
Liczba postów: 2,456
Liczba wątków: 0
Dołączył: Oct 2017
Reputacja:
247
Opis problemu jest niekompletny, jaki schemat, kod, biblioteka i skąd. W jednej bibliotece może to się robi inaczej niż w innej, trudno zgadnąć co tam masz.
Liczba postów: 4
Liczba wątków: 1
Dołączył: Oct 2017
Reputacja:
0
08-02-2025, 11:02
(Ten post był ostatnio modyfikowany: 08-02-2025, 12:14 przez Truck.)
Udało mi się uruchomić wysyłanie danych. Rozbudowałem program o odbiór danych (listing poniżej). Wysyłanie danych działa, sygnał z modułu XBee dochodzi do wejścia portu Serial1, ale program nie odbiera danych.
#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();
//Rx16Response rx = Rx16Response();
uint8_t payload[20]; // zmienna hex na dane do wysłania
uint16_t addr16 = 0x0000;
Tx16Request zbTx = Tx16Request(addr16, payload, sizeof(payload));
int statusLed = 13;
int errorLed = 13;
int dataLed = 13;
void flashLed(int pin, int times, int wait) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);
if (i + 1 < times) {
delay(wait);
}
}
}
void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
pinMode(dataLed, OUTPUT);
XBee xbee = XBee();
// Start the serial port
Serial1.begin(57600);
// Tell XBee to use Hardware Serial. It's also possible to use SoftwareSerial
xbee.setSerial(Serial1);
Serial.begin(9600);
Serial.println("Start");
flashLed(statusLed, 3, 50);
addr16 = 0;
payload[0] = 'O';
payload[1] = 'K';
payload[2] = '!';
zbTx = Tx16Request(addr16, payload, 3);
xbee.send(zbTx); // wysylanie potwierdzenia
}
// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {
xbee.readPacket();
// Serial.println("readPacket");
if (xbee.getResponse().isAvailable()) {
// got something
Serial.println("isAvailable");
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
// got a zb rx packet
// now fill our zb rx class
xbee.getResponse().getZBRxResponse(rx);
Serial.println("Dane");
// set dataLed PWM to value of the first byte in the data
analogWrite(dataLed, rx.getData(0));
}
}
}
Liczba postów: 4
Liczba wątków: 1
Dołączył: Oct 2017
Reputacja:
0
Dziękuję za pomoc. Układ zadziałał.