Forum Navigation
Please or Register to create posts and topics.

Temperature sensor

I was discussing with Ron about adding a temperature sensor which reads the actual temperature in the sims cockpit.
Since i use the Airmanager  software i said this must be possible.
Well after some struggling it IS!

I use a DHT11 temp sensor which also can read humidity and send the temp in Celscius as in Fahrenheit.
Using DHT11 | Arduino Project Hub

For use with Airmanager you have to use the "messageport" option, this means adding this library and include it in the Arduino script.
The Arduino then takes over the control of this sensor and send as requested by AM the temp.

Arduino C++ code:

#include <si_message_port.hpp>
#include "DHT.h"
#define DHT11_PIN 14
DHT dht11(DHT11_PIN, DHT11);
SiMessagePort* messagePort;
// Setup section
void setup() {
    // Initialize the message port on Channel A with the callback function
    messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_MEGA_2560, SI_MESSAGE_PORT_CHANNEL_A, new_message_callback);
}
// function called everytime a message is received from Air Manager
static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
    if (message_id == 777 && payload != NULL && payload->type == SI_MESSAGE_PORT_DATA_TYPE_STRING) {
        uint8_t* length = payload->len; // returns the length of the payload (not used)
        String command = payload->data_string;// stores the payload in a string <----- modified
        if (command.equals("TEMP") == true){ //equals compares two strings and returns true/false <----- modified
           // read temperature as Celsius
          float tempC = dht11.readTemperature();
            // Send acknowledgment back to Air Manager
            messagePort->SendMessage(777, tempC); // Float
        }
    } else {
        // Do Nothing
    }
    dht11.begin(); // initialize the sensor
}
void loop() {
    messagePort->Tick();  // Regularly calls this to process incoming messages
}
In short what this code does is when the Arduino receives a number of 777 from AM , it sends back the temperature value (in this case in Celsius)
On the AM side the LUA script looks like this:

-- This function will be called when a message is received from the Arduino.
function new_message(id, payload)
-- Do something with the message from the Arduino
print("message received: "..id.." "..payload)
Temp_read = math.floor(payload)
print(Temp_read)
txt_set(txt_TAT, Temp_read)
end

id = hw_message_port_add("ARDUINO_MEGA2560_A", new_message)

-------------------------------------

-- Send a message to the Arduino with id 777 and

-- This function will be called every 2 seconds
function messageport_timer_callback(count)
flipflop= not flipflop --switches the value with every call
if flipflop == true then
hw_message_port_send(id, 777, "STRING", "TEMP")
end
end
timer_start(0, 2000, messageport_timer_callback)

 

In short:

I made a timer which now sends every 2 seconds a request with the value of 777 to trigger the Arduino to send the temperature value.
This value is put in a AM variable to show on the EICAS display

Values received in AM console:

Shown on EICAS

Great idea from Ron
i only have to implement it in the Sim.

Uploaded files:
  • You need to login to have access to uploads.
Ron Rollo has reacted to this post.
Ron Rollo

Hey Roel,

Glad to see that you got this working!  Truth be told, the idea of using temp sensors originated with DonnyRay a couple years ago except his idea was to have several temp sensors monitoring the batteries, cockpit temp, cabin temp, the center pedestal and a couple other places that monitor temperatures.

I personally didn't think it was necessary to  have temp sensors in places where we would not be able to replicate temperatures that replicate batteries overheating as an example.  We could model batteries getting warm or overheating in software much easier than modeling a real heat source to replicate batteries overheating that are not actually there.

But in the case of the Cabin Temp, this is a real thing that we can detect as we are in the cockpit.  It beats the static display that never changes!

Great work Roel!  By the way, I know I have said this a dozen times, but every time I see a bunch of code like what you have posted above, it's mind boggling to me how you guys can read, understand and make it work.