Community
cancel
Showing results for 
Search instead for 
Did you mean: 
JCarv5
Novice
1,868 Views

DHT11 C wrapper for Arduino Code

I am trying to create a C code wrapper to run the Arduino code for reading from DHT11 temperature and humidity sensor on a Galileo Gen 2.

The Arduino code I am using is from this discussion:

I was wondering how to run the program on demand rather than continuously as the Arduino code does.

0 Kudos
11 Replies
FTinetti
Honored Contributor I
174 Views

milesZappa wrote:

I am trying to create a C code wrapper to run the Arduino code for reading from DHT11 temperature and humidity sensor on a Galileo Gen 2.

The Arduino code I am using is from this discussion:

/thread/53869 DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one

I was wondering how to run the program on demand rather than continuously as the Arduino code does.

My suggestion would be

a) Check your sketch is running fine

b) Change writing on Serial to write to a file

c) Read the file

Another method would be making a pipe, but I think the "file method" is good enough, mostly because reading this sensor would be needed in a rather low frequency.

In case you already have the sketch running fine and do not know about how to do b) and c) just let me know and I'll try to help.

HTH,

Fernando.

idata
Community Manager
174 Views

Hello milesZappa,

 

 

I was wondering if you could check the suggestions provided by FGT.

 

 

If you have any update or question, don't hesitate to contact us.

 

 

Regards,

 

Andres V.
JHrib
New Contributor II
174 Views

Hi, Fernando.

This post seems interesting and I was just wondering if it is possible to run Arduino code on demand when you are in Linux environment? Is it like some sort of bash script like method.

For example:

Command_to_run_arduini_code arduino_file

What would be command and how can we generate arduino_file?

Kind regards

Jernej

FTinetti
Honored Contributor I
174 Views

JernejH wrote:

Hi, Fernando.

This post seems interesting and I was just wondering if it is possible to run Arduino code on demand when you are in Linux environment? Is it like some sort of bash script like method.

For example:

Command_to_run_arduini_code arduino_file

What would be command and how can we generate arduino_file?

Kind regards

Jernej

Step 1: generate the sketch binary, which is made in the Arduino IDE.

Step 2: upload the sketch to the Intel Galileo, which is made in the Arduino IDE. The Arduino IDE uploads the sketch binary and automatically runs it. I'd suggest you rename the binary:

$ mv /sketch/sketch.elf /sketch/

reboot the Intel Galileo so that the sketch stops running/using resources (or, alternatively, kill the sketch process)

Step 3: run the sketch with , e.g. in a command line

$

Remember all the sketches run forever, so take into account that once you run a sketch it does not end running unless you explicitly kill the process (e.g. $ killall )

HTH,

Fernando.

JHrib
New Contributor II
174 Views

Hi, Fernando.

This is very interesting. I have two follow-up questions>

1. Is it possible to make sketch do something and then stop automatically? In the case of DHT, it could be used to write to a file and then terminate until the sketch is called again. Does Arduino code allow to be without void loop()?

2. The other question I have is related to computing resources. If we assume, we have an Arduino sketch which reads from DHT11 sensor every 5 minutes( for example we use delay(300000) in void loop()). How would this impact available computing resources of another program we may run along side it. By this I mean if I have Arduino sketch running, and then I run a python script, will the python script run normally?

Kind regards

Jernej

FTinetti
Honored Contributor I
174 Views

JernejH wrote:

Hi, Fernando.

This is very interesting. I have two follow-up questions>

1. Is it possible to make sketch do something and then stop automatically? In the case of DHT, it could be used to write to a file and then terminate until the sketch is called again. Does Arduino code allow to be without void loop()?

2. The other question I have is related to computing resources. If we assume, we have an Arduino sketch which reads from DHT11 sensor every 5 minutes( for example we use delay(300000) in void loop()). How would this impact available computing resources of another program we may run along side it. By this I mean if I have Arduino sketch running, and then I run a python script, will the python script run normally?

Kind regards

Jernej

Hi Jernej,

About 1)

I think there is no way to make Arduino sketches without loop()... but in the case of Galileo maybe there are some alternatives in order to end the running the sketch. The ones I think possible are not very elegant, though...

a) The sketch itself may use system("killall sketch.elf")... I don't know if it's going to work, but you can give it a try.

b) Given you will start the sketch from another process (e.g. from bash command line) that same process may use killall to end the sketch. Adding a little bit of code, you will be able to verify that the file contains the DHT data and at that time end the sketch.

About 2)

Having a sequence of a) DHT reading/s, b) save reading/s in file, c) delay(300000) will let the Linux OS mostly idle, since none of those tasks are particularly time or resource consuming. I think a python script will run almost normally.

HTH,

Fernando.

JHrib
New Contributor II
174 Views

Hi, Fernando.

Thank you. I will test and then report back. However, I still have one more question. Is it possible to copy the sketch and to use it on multiple Galileos? If sketch has to be loaded on every Galileo manually, it could be very time-consuming.

Kind regards

Jernej

FTinetti
Honored Contributor I
174 Views

JernejH wrote:

Hi, Fernando.

Thank you. I will test and then report back. However, I still have one more question. Is it possible to copy the sketch and to use it on multiple Galileos?

Identical Intel Galileo, identical hardware (e.g. DHT11): yes.

Two details:

1) I'd evelop-test-etc. in one Intel Galileo and then copy the SD card.

2) Take into account that if you use the previous method and have fixed IP's in the same LAN then you'll have to set the specific IPs card-by-card.

HTH,

Fernando.

JHrib
New Contributor II
174 Views

Hi, Fernando.

I was able to run sketch like this:

chmod +x

./ /dev/ttyS0> /dev/null 2>&1 &

as described in /thread/48813 https://communities.intel.com/thread/48813

It works, I still have to copy the sketch from one image to another to see if that would work. I tested it with blink basic example, not the DHT example.

Kind regards

Jernej

JCarv5
Novice
174 Views

Rather than writing a wrapper for the Arduino library, I modified it to work in C++ for Galileo Gen 2.

The code is attached.

FTinetti
Honored Contributor I
174 Views

Thank you

Why do you need/use mraa?

Fernando.

Reply