This is the code:
//Lora with Transmitter arduino nano
#include <SPI.h> // include libraries
#include <LoRa.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <LM75A.h>
LM75A lm75a_sensor(false, // A0 LM75A pin state (connected to ground = false)
false, // A1 LM75A pin state (connected to ground = false)
false); // A2 LM75A pin state (connected to ground = false)
// Equivalent to "LM75A lm75a_sensor;"
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
String outgoing; // outgoing message
byte msgCount = 0; // count of outgoing messages
byte MasterNode = 0xFF;
byte Node1 = 0xBB;
float ctemp;
float ftemp;
String Mymessage = "";
void setup() {
Serial.begin(9600); // initialize serial
Wire.begin();
if (!LoRa.begin(433E6)) {
Serial.println("LoRa init failed. Check your connections.");
while (true); // if failed, do nothing
}
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
}
void loop() {
float temperature_in_degrees = lm75a_sensor.getTemperatureInDegrees();
if (temperature_in_degrees == INVALID_LM75A_TEMPERATURE)
{
Serial.println("Error while getting temperature");
}
else
{
// Serial.print("Temperature: ");
// Serial.print(temperature_in_degrees);
// Serial.print(" degrees ");
//Serial.print(LM75A::degreesToFahrenheit(temperature_in_degrees));
ftemp= LM75A::degreesToFahrenheit(temperature_in_degrees);
// Serial.print(ftemp);
// Serial.println(" fahrenheit)");
display.clearDisplay();
display.setCursor(25,0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println(" Temperature");
display.setCursor(10,20);
display.setTextSize(2);
//display.print("C: ");
display.print(temperature_in_degrees);
display.print((char)247);
display.print("C");
display.setCursor(10,45);
display.setTextSize(2);
//display.print("F: ");
display.print(ftemp);
display.print((char)247);
display.print("F");
display.display();
Mymessage = Mymessage + temperature_in_degrees + "," + ftemp;
sendMessage(Mymessage,MasterNode,Node1);
delay(100);
Mymessage = "";
}
}
void sendMessage(String outgoing, byte MasterNode, byte otherNode) {
LoRa.beginPacket(); // start packet
LoRa.write(MasterNode); // add destination address
LoRa.write(Node1); // add sender address
LoRa.write(msgCount); // add message ID
LoRa.write(outgoing.length()); // add payload length
LoRa.print(outgoing); // add payload
LoRa.endPacket(); // finish packet and send it
msgCount++; // increment message ID
}
I am struggling to get the Oled LCD screen to show any data collected by the temperature sensor I have connected in the circuit. Would this be a coding issue or is it down to an incorrect wire connection. I am using an arduino nano board as the microcontroller in the circuit.