Arduino + SR120U

Ciao a tutti, sto cercando di far funzionare Arduino e il modulo SR120U

Sono riuscito a far comunicare i codici AT con questo codice che metto, infatti il modulo restituisce "+DMOGRP:0" che è appunto un messaggio di avvenuto successo, tuttavia non riesco ne ad aprire il canale mandando a ground il PTT e nemmeno a ricevere un audio da un'altra radio che è impostata su quello specifico canale.

La domanda da ignorante, l'antenna è essenziale per la ricezione\invio? Mi spiego, se metto la trasmittente radio molto vicino al cavo che ho saldato sul pin dell'antenna dovrebbe ricevere qualcosa? Oppure no. Perchè a quel punto sarebbe quello il problema.

Ho trovato vari progetti con un modulo simile o identico.

Negozio aliexpress modulo

progetto instructables con stesso modulo

scheda progetto

datasheet

altro progetto simile

Grazie per aver letto fin qui e dell'eventuale aiuto.

PS: So che devo mettere i filtri e l'altra elettronica, ma vorrei prima vedere se il modulo riceve (fra l'altro mi serve per ricezione più che per invio)

EDIT:

Il problema è che stavo inviando i dati in stringa, mentre il modulo li vuole in formato HEX

Con questo codice ho impostato la radio sul canale 450.025000 seguendo l'esempio su datasheet:

41 54 2B 44 4D 4F 47 52 50 3D 34 35 30 2E 30 32 35 30 30 2C 34 35 30 2E 30 32 35
30 30 2C FF FF 2C FF FF 2C 30 2C 30 0D 0A

Con questo esempio si impostano

Dove FF sta per impostazione disattivata

AT+DMOGRP=450.02500,450.02500,FF,FF,0,0\r\n

Con questo programma il modulo è stato impostato sulla frequenza e funziona anche con una antenna spartana. Ora integrerò l'altra elettronica.



/*************************************************
   Public Constants
 *************************************************/

#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978

// Pins for UART communication
#define RXD_PIN 19 // Arduino Mega RX (connect to module's TXD)
#define TXD_PIN 18 // Arduino Mega TX (connect to module's RXD)
#define PTT_PIN 7  // Push-to-talk control (connect to module's PTT)
#define PD_PIN 8   // Power-down control (connect to module's PD)


// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};
// HEX data to be sent
byte hexData[] = {

  0x41, 0x54, 0x2B, 0x44, 0x4D, 0x4F, 0x47, 0x52, 0x50, 0x3D,   // AT+DMOGRP=
  0x34, 0x34, 0x36, 0x2E, 0x30, 0x30, 0x36, 0x32, 0x35,         // 446.0625
  0x2C, //, 
  0x34, 0x34, 0x36, 0x2E, 0x30, 0x30, 0x36, 0x32, 0x35,         // 446.0625 
  0x2C, //, 
  0xFF, 0xFF, 
  0x2C, //, 
  0xFF, // FF non active function
  0xFF, // FF non active function
  0x2C, //, 
  0x30, // 0 
  0x2C, //, 
  0x30, // 0 
  0x0D, // \r
  0x0A // \n




};

void setup() {
  // Initialize serial communication
  Serial.begin(9600);   // Debugging output
  Serial1.begin(9600);  // Communication with SR-FRS module

  // Configure control pins
  pinMode(PTT_PIN, OUTPUT);
  pinMode(PD_PIN, OUTPUT);

  // Activate the module
  powerOnModule();

  // Send the HEX data
  sendHexData(hexData, sizeof(hexData));

  // Read and display the reply from the module
  String reply = readModuleReply();
  Serial.println("Module Reply: " + reply);



}

void loop() {

  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
  }


}

// Function to power on the module
void powerOnModule() {
  digitalWrite(PD_PIN, HIGH); // Wake up the module
  digitalWrite(PTT_PIN, HIGH); // Set to receive mode
  delay(500); // Allow the module to initialize
}

// Function to send the HEX data to the module
void sendHexData(byte* data, size_t length) {
  Serial.println("Sending HEX data:"); // Debugging output
  for (size_t i = 0; i < length; i++) {
    Serial.print(data[i], HEX); // Print HEX data to Serial Monitor for debugging
    Serial.print(" ");
    Serial1.write(data[i]); // Send each byte to the module
  }
  Serial.println(); // Newline for readability
}

// Function to read the reply from the module
String readModuleReply() {
  String response = "";              // Variable to hold the response
  unsigned long startTime = millis(); // Start time for timeout
  const unsigned long timeout = 500; // Timeout duration (5 seconds)

  while (millis() - startTime < timeout) {
    while (Serial1.available()) {    // Check if data is available from the module
      char c = Serial1.read();       // Read the incoming byte
      response += c;                 // Append to the response string
    }
  }

  // Check if a response was received
  if (response.length() == 0) {
    return "No reply received within timeout.";
  }

  return response; // Return the full response
}

Buongiorno e benvenuto nella sezione Italiana del forum,

cortesemente, come prima cosa, leggi attentamente il REGOLAMENTO di detta sezione, (... e, per evitare future possibili discussioni/incomprensioni, prestando molta attenzione al punto 15), dopo di che, come da suddetto regolamento (punto 16.7), fai la tua presentazione NELL'APPOSITA DISCUSSIONE (... quello che vedi in blu è un link, fai click su di esso per raggiungere la discussione) spiegando bene quali esperienze hai in elettronica e programmazione, affinché noi possiamo conoscere la tua esperienza ed esprimerci con termini adeguati.

Grazie,

Guglielmo

P.S.: Ti ricordo che, purtroppo, fino a quando non sarà fatta la presentazione nell’apposita discussione, nel rispetto del succitato regolamento nessuno ti risponderà (eventuali risposte o tuoi ulteriori post, verrebbero temporaneamente nascosti), quindi ti consiglio di farla al più presto. :wink:

Ciao Guglielmo, sono dal forum da più di 12 anni! Sicuro che non hai trovato il mio vecchio post di presentazione? Sarà archeologia digitale ormai :smile: . Ad onor del vero anche io non lo trovo più, quindi lo rifaccio :slight_smile: ! Grazie e a presto.

So che sei un vecchio utente :grin: ... ma il post di presentazione NON c'è, anche perché ... i tuoi post sono tutti nella sezione internazionale e non ne trovo altri nella sezione Italiana (... che ha il suo REGOLAMENTO) :wink:

Guglielmo

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.