Go Down

Topic: 433 Mhz modules don't output to OLED (Read 250 times) previous topic - next topic

Oiitsjamesmate

Gday guys, first post on the forums!

I am having some troubles with my Arduino project. I have 2x 433mhz wireless modules working on 2 Arduino Nanos and I have a successful connection between the 2 devices. I am trying to send "15" from one Arduino to another and I can pick it up using the serial monitor (with 15 randomized characters tacked on the end for some reason but ill add some code to just read the first part of the transmission) but I cannot display the message on my OLED screen. My wiring diagrams and code are attached.




 Recieving Code:
Code: [Select]
//Recieving Remote Software

// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>

// Include Dependant SPI Library
#include <SPI.h>

//Include U8GLIB Library
#include "U8glib.h"

//Declaring the OLED Screen
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

//Drawing the Splash Screen
void draw_splash(void){
u8g.setFont(u8g_font_unifont);
 u8g.drawStr(16, 12,"Initializing");
 u8g.drawStr(10, 24,"------- ");
 u8g.drawStr(26, 36,"Electronic");
 u8g.drawStr(28, 48,"Longboard");
 u8g.drawStr(18, 60,"Smart Remote"); 
}

//Drawing the Main Screen
void draw_main(void) {

//Drawing Headings and Lines
 u8g.setFont(u8g_font_unifont);
 u8g.drawStr(11, 12,"Speed");
 u8g.setFont(u8g_font_unifont );
 u8g.drawStr(70, 12,"Battery");
 u8g.drawLine(66,0,66,64);
 u8g.drawLine(0,16,128,16);

//Drawing Battery 1
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawFrame(104,25,22,10);
  u8g.drawBox(126,28,2,4);

//Drawing Battery 1 Variables
  u8g.setFont(u8g_font_unifont);
  u8g.drawStr(68, 35,"100%");
  u8g.drawBox(106,27,18,6);

//Drawing Battery 2
  u8g.setFont(u8g_font_unifont);
  u8g.drawFrame(104,50,22,10);
  u8g.drawBox(126,53,2,4);

//Drawing Battery 2 Variables
  u8g.setFont(u8g_font_unifont);
  u8g.drawStr(68, 60,"100%");
  u8g.drawBox(106,52,18,6);
   
}

//Setup Code
void setup(void) {
   // Initialize ASK Object
    rf_driver.init();
   //Setup Serial Monitor
   Serial.begin(9600);
}

//Loop Code
void loop(void){
 
// Set buffer to size of expected message
uint8_t buf [2];
uint8_t buflen = sizeof(buf);
// Check if received packet is correct size
if (rf_driver.recv(buf, &buflen))
    {
      Serial.println((char*)buf);
      u8g.setPrintPos(4,62);
      u8g.setFont(u8g_font_fub35n);
      u8g.print((char*)buf);
    }

//Code that switches from Splash Screen to Main Screen after 5 seconds
if(millis()<5000){
  u8g.firstPage(); 
  do {
    draw_splash();
  } while( u8g.nextPage() );
  }else{
 
  u8g.firstPage(); 
    do {
      draw_main();
    } while( u8g.nextPage() );
 
     // rebuild the picture after some delay
       delay(50);
  }
}

Transmitting Code:
Code: [Select]
//Transmitting Remote Software

// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>
 
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

//Define Variables
float kmph;    // Stores kmph value in kmph
float batR;   // Stores battery (remote) value in percent
float batS;   // Stores battery (skateboard) value in percent

//Define Output Strings
String str_kmph;
String str_batR;
String str_batS;
String str_out;

void setup()
{
    // Initialize ASK Object
    rf_driver.init();
}
 
void loop()
{
    const char *msg = "15";
    rf_driver.send((uint8_t *)msg, strlen(msg));
    rf_driver.waitPacketSent();
    delay(1000);
}


I am having trouble with the receiving code (specifically this part as it does pop up on the serial monitor but not the OLED. I'm assuming its something wrong with the u8g.println part.)

Code: [Select]
// Set buffer to size of expected message
uint8_t buf [2];
uint8_t buflen = sizeof(buf);
// Check if received packet is correct size
if (rf_driver.recv(buf, &buflen))
    {
      Serial.println((char*)buf);
      u8g.setPrintPos(4,62);
      u8g.setFont(u8g_font_fub35n);
      u8g.print((char*)buf);


Thank you guys so much <3

georgegs

Hi, please try to put a capacitor (10-100uF) between DataPin and Ground on the receiver, this should filter your signal.

Regards.

Oiitsjamesmate

My arduino does not pick up any signal from the transmitter if I put a 100uF or a 100uF capacitor between the data and ground pin.

jremington

#3
Jun 27, 2018, 01:45 am Last Edit: Jun 27, 2018, 01:49 am by jremington
Quote
(with 15 randomized characters tacked on the end for some reason)
The way you are sending the message does not transmit the zero terminator of the C-string. That is why you get the extra characters.

You MUST reserve space for that zero, and add it back in when the message is received.

Try the following:

Code: [Select]
// Set buffer to size of expected message PLUS zero terminator
uint8_t buf [3];
uint8_t buflen = sizeof(buf);
if (rf_driver.recv(buf, &buflen))
   {
    buf[2]=0; //make sure to terminate string
    Serial.println( (char *) buf);

Oiitsjamesmate

The way you are sending the message does not transmit the zero terminator of the C-string. That is why you get the extra characters.

You MUST reserve space for that zero, and add it back in when the message is received.

Try the following:

Code: [Select]
// Set buffer to size of expected message PLUS zero terminator
uint8_t buf [3];
uint8_t buflen = sizeof(buf);
// Check if received packet is correct size
if (rf_driver.recv(buf, &buflen))
   {
    buf[2]=0; //make sure to terminate string
    Serial.println( (char *) buf);


Thank you very much this worked a treat. Now I just need to solve the issue of printing it to the OLED.

jremington

Quote
please try to put a capacitor (10-100uF) between DataPin and Ground on the receiver
I think you mean Vcc and GND. It does not make sense to put one between Data and GND.

Oiitsjamesmate

Would it be a good solution to read the latest line of the serial monitor and output it to the oled?

jremington

#7
Jun 27, 2018, 04:46 am Last Edit: Jun 27, 2018, 04:47 am by jremington
Sorry, I don't understand what you mean by "the latest line of the serial monitor".

You MUST add that terminating zero no matter where you send the received string. The zero is required to define the end of the string, and is required to determine its length.

Oiitsjamesmate

Thank you so much for your help guys. I have worked through my project but I have met another bump in the road. Will post to a new topic.

Go Up