Need help please , I'm a beginner and i'd like to transmite data from the ultrasonic sensor and i'd like to display the data on ssd oled 1306 .i'm using Lora module.
Really sorry for my english.
Break your problem down into part.
Learn how to read an ultrasonic sensor (plenty of examples and libraries out there)
Learn how to send and receive data over LoRa (again, libraries and examples)
Learn how to display data on an OLED display (I bet you can guess what is supposed to be between these parentheses)
Thanks for thank you for your reply,
I know as well how to use ultrasonic and oled display but the problem is the lora, How to transmite and how to recive data?
There is my code , can I have a help on TX and RX part ?
Thanks
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Déclaration pour un afficheur SSD1306 connecté en I2C (broches SDA, SCL)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//DĂ©finir les connexions au capteur
#define TRIGPIN 5
#define ECHOPIN 18
//définir la vitesse du son en cm/uS
#define SOUND_SPEED 0.034
#define CM_TO_LITER 76
// Floats to calculate distance
float duration, distance,liter;
byte hniveaumaxi=21.20;
byte hniveaumini=309;
void setup() {
Serial.begin(115200);
pinMode(TRIGPIN, OUTPUT); // Sets the trigPin as an Output
pinMode(ECHOPIN, INPUT); // Sets the echoPin as an Input
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(500);
display.clearDisplay();
display.setTextSize(1.5);
display.setTextColor(WHITE);
// Configuration du moniteur serie
Serial.begin(115200);
// definir les connections broche-capteur
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
}
void loop() {
// desactiver la broche trigpin pour 2 microseconde
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
// activer la broche trigpin pour 20 microseconde pour envoyer une impulsion
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(20);
// re-desactiver la broche trigpin
digitalWrite(TRIGPIN, LOW);
// Mesure de largeur de l'impulsion entrante
duration = pulseIn(ECHOPIN, HIGH);
// Déterminer la distance de la durée
// Utiliser 343 mètres par seconde comme vitesse du son
distance = (duration / 2) * 0.0343;
// Convertion en litre
liter = -((distance-309)/0.01315068493) ;
// Ecriture des resultats au moniteur serie
Serial.print("distance (cm): ");
Serial.println(distance);
Serial.print("liter(L): ");
Serial.println(liter);
display.clearDisplay();
display.setCursor(0, 25);
//Affichage de distance en cm et en liter
display.print(distance);
display.print(" cm ");
display.print(liter);
display.print(" L");
// Affichage distance in liter
/* display.print(distanceliter);
display.print(" in");*/
display.display();
delay(100);
// Délai avant de répéter la mesure
delay(100);
}
Have you looked at the example code for your unnamed radio module?
unfortunately i didn't find any correct information of the module as it is a chinese module but it is an 433mhz lora module TTL 3-5 Km.
I've already tried to code the TX and Rx but it does not work
there is the TX code:
void loop(){
// desactiver la broche trigpin pour 2 microseconde
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
// activer la broche trigpin pour 20 microseconde pour envoyer une impulsion
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(20);
// re-desactiver la broche trigpin
digitalWrite(TRIGPIN, LOW);
// Mesure de largeur de l'impulsion entrante
duration = pulseIn(ECHOPIN, HIGH);
// Déterminer la distance de la durée
// Utiliser 343 mètres par seconde comme vitesse de l'ultrason
distance = (duration / 2) * 0.0343;
// Convertion en litre
liter = -((distance-309)/0.01315068493) ;
//en pourcentage
pourcent=0.00456621005*liter;
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
Serial.print("distance (cm): ");
Serial.println(distance);
Serial.print("liter(L): ");
Serial.println(liter);
Serial.print("pourcent (%): ");
Serial.println(pourcent);
LoRa.beginPacket(); ///send packet
LoRa.print("distance (cm): ");
LoRa.print("liter(L): ");
LoRa.print("pourcent (%): ");
LoRa.endPacket();
delay(200);
}
and the RX side is:
#include<LoRa.h>
#include <SPI.h> // Not actually used but needed to compile
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Déclaration pour un afficheur SSD1306 connecté en I2C (broches SDA, SCL)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
{
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(500);
display.clearDisplay();
display.setTextSize(1.5);
display.setTextColor(WHITE);;
while (!Serial);
Serial.println("LoRa Receiver");
if (!LoRa.begin(433E6))
{
Serial.println("Starting LoRa failed!");
while (1);
// LoRa.setTxPower(20);
}
LoRa.setSpreadingFactor(10);
LoRa.setSignalBandwidth(62.5E3);
LoRa.crc();
}
}
void loop()
{
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize)
{
// received a packet
// Serial.print("distance is ");
// read packet
// while (LoRa.available()) {
// Serial.print((char)LoRa.read());
// }
int distance,liter,pourcent = LoRa.parseInt();
// Serial.print(distance);
// Serial.print(" cm ");
// Serial.println(" ");
display.clearDisplay();
display.setCursor(0, 25);
//Affichage de distance en cm et en liter
display.print(distance);
display.print(" cm ");
display.print(liter);
display.print(" L");
// Affichage distance in liter
/* display.print(distanceliter);
display.print(" in");*/
display.display();
delay(100);
}
}
As an example here are working transmitter and receiver programs for a LoRa setup that reads a BME280 sensor, sends the values to be received by the remote receiver and then goes into a low current sleep mode.
The receiver is another Arduino that receives the data from the transmitter and displays it on an SSD1306 display;
It makes it very difficult to provide meaningful help, with your code, if you do not provide specific information of the 'LoRa' modules you are actually using.
Thanks, i'm trying to study this right now
Thats not a base 'LoRa' module at all.
It looks like a UART front ended module, accessed via a Serial port connection.
So all the standard and usual libraries for the SPI based LoRa modules wont work at all.
Hi, @litakely95
Welcome to the forum.
Can you please post a link to where you purchased and data/specs on your Lora module?
Thanks.. Tom..
Hi, @TomGeorge
thank you very much.
i din't buy this module online, I bought it in a local electronics store and the label only shows ''0,1W; 433MHz ; 3-5 Km TTL LoRa module''
Thanks...Lita
Hi,@srnet
So how can i send the data?
Your help would be very useful to me
Thanks
No idea, those type of modules dont follow a 'standard' method of using them.
You really need the datasheet for the module.
You could try poking some serial data into see if anything happens, but it would be heaps easier to buy modules that you have a datasheet for.
Hi,
Finaly i found the reference of the item:
https://m.fr.aliexpress.com/item/32372642473.html
Thanks
Try seeing if you can adapt a Si4432 driver.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.