Linkan
Posts: 30
Joined: Tue Feb 10, 2015 3:56 pm

Using SenseHAT from C

Mon Mar 07, 2016 1:52 pm

Hi,

How do I access the sense hat using only C? I looked in the snake example written in C but I need to know how I can access the humidity/barometer/temperature sensors.

I'd be very grateful if you anyone could provide me with an example in C on how I can fetch humidity level for example. :D

scotty101
Posts: 3734
Joined: Fri Jun 08, 2012 6:03 pm

Re: Using SenseHAT from C

Mon Mar 07, 2016 2:10 pm

The Sense hat makes use of the RTIMU library which is written for C++.

https://github.com/richards-tech/RTIMULib

You might be able to write a C wrapper for this code.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
experix
Posts: 204
Joined: Mon Nov 10, 2014 7:39 pm
Location: Coquille OR
Contact: Website

Re: Using SenseHAT from C

Mon Mar 07, 2016 2:22 pm

I made example programs that operate the LED matrix; get joystick input; and monitor temperature reported by the pressure sensor, temperature/humidity sensor, accelerometer and CPU. Find it in https://experix.sourceforge.net. Click Dowload source files and information, select sense-hat, download the archive and follow directions in the README (which is displayed under the file list). This is as 'basic' as you can get, not using RTIMULib; I'm trying to start with fundamentals and go up from there.

Linkan
Posts: 30
Joined: Tue Feb 10, 2015 3:56 pm

Re: Using SenseHAT from C

Wed Mar 09, 2016 9:31 pm

experix wrote:I made example programs that operate the LED matrix; get joystick input; and monitor temperature reported by the pressure sensor, temperature/humidity sensor, accelerometer and CPU. Find it in https://experix.sourceforge.net. Click Dowload source files and information, select sense-hat, download the archive and follow directions in the README (which is displayed under the file list). This is as 'basic' as you can get, not using RTIMULib; I'm trying to start with fundamentals and go up from there.
Thanks for the example code. I understood from the code that temperature.c shows the temperatures provided from the pressure sensor and temperature/humidity sensor but how can I obtain the pressure (in mbars) and humidity (as a percentage)?

Would this code work?

Code: Select all

    // get a LPS25H pressure sample
    res = ioctl( i2c, I2C_SLAVE, LPS25H_SAD );
    buf[0] = LPS25H_STATUS_REG;
    res = write( i2c, buf, 1 );
    res = read( i2c, buf, 2 );
    LPS25H_status = buf[0];
    buf[0] = LPS25H_FIFO_STATUS;
    res = write( i2c, buf, 1 );
    res = read( i2c, buf, 2 );
    LPS25H_fifo_status = buf[0];
    buf[0] = LPS25H_PRESS_POUT | LPS25H_reg_auto;
    res = write( i2c, buf, 1 );
    res = read( i2c, buf, 2 );
    LPS25Hd16[ii] = ((__s16 *)buf)[0];

User avatar
experix
Posts: 204
Joined: Mon Nov 10, 2014 7:39 pm
Location: Coquille OR
Contact: Website

Re: Using SenseHAT from C

Thu Mar 10, 2016 2:41 pm

I am taking little baby steps with this and trying to explore all aspects of the problem. Consequently I have not yet gotten around to the humidity and pressure. With the help of the datasheet you should be able to adapt my code to read those things. My equipment is packed in a moving pod and it will be several months before I begin to work on this again.

Linkan
Posts: 30
Joined: Tue Feb 10, 2015 3:56 pm

Re: Using SenseHAT from C

Thu Mar 10, 2016 3:01 pm

experix wrote:I am taking little baby steps with this and trying to explore all aspects of the problem. Consequently I have not yet gotten around to the humidity and pressure. With the help of the datasheet you should be able to adapt my code to read those things. My equipment is packed in a moving pod and it will be several months before I begin to work on this again.
Okay, I will see what I can do. I'm certainly not an expert in this area but perhaps I can look at the source code of [this](https://github.com/RPi-Distro/RTIMULib) fork of RTIMULib.

Linkan
Posts: 30
Joined: Tue Feb 10, 2015 3:56 pm

Re: Using SenseHAT from C

Fri Apr 01, 2016 1:45 pm

basicsensor.tar.gz
(5.41 KiB) Downloaded 483 times
For any curious future readers, I did get it working based on experix code. See attachment for details. Note I tried minimizing this as much as possible so it isn't necessarily complete.

User avatar
John_Spikowski
Posts: 1509
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Using SenseHAT from C

Thu Apr 04, 2019 5:24 am

Can I use the Sense Hat emuator with your basicsensors.c example?

Return to “Astro Pi”