- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm using the IOTDK Eclipse IDE to compile a C program using the MRAA. I'm trying to do a basic read to see if the Arduino pins are high or low, this program in particular looks at pin 8 and sends the output to stdout. I'm basing my program off of this: http://iotdk.intel.com/docs/master/mraa/gpio_8h.html
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "mraa/gpio.h"
int main(int argc, char **argv)
{
mraa_gpio_context gpio8;
gpio8=mraa_gpio_init(8);
mraa_gpio_dir(gpio8, MRAA_GPIO_IN);
for (;;) {
fprintf(stdout, "The value of pin 8 is: %d\n", gpio8);
sleep(1);
}
I'm getting the following output:
The value of pin 8 is: 143212968
The value of pin 8 is: 143212968
... and so on. What does this integer mean, and how do I determine if this is high or low? Thanks!
- Tags:
- Internet of Things
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jim.
That integer looks to be the memory location of the gpio8 structure. I think you need to read the pin value with:
fprintf(stdout, "The value of pin 8 is %d\n", mraa_gpio_read(gpio8));
See http://iotdk.intel.com/docs/master/mraa/gpio_8h.html
Brian
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
not answering your question but in general:
which platform are you on?
have you latest MRAA running on your target?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm on the galileo gen 2 running the latest iotdk image. I've done a board firmware upgrade via the arduino console (not related im guessing) and also run opkg update and opkg upgrade, so not really sure what version of mraa. I would just use the arduino ide, but I'd like to export the data into a JSON and send that out, so I figured a C or python script would do the trick best?
Thanks for the interest,
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jim.
That integer looks to be the memory location of the gpio8 structure. I think you need to read the pin value with:
fprintf(stdout, "The value of pin 8 is %d\n", mraa_gpio_read(gpio8));
See http://iotdk.intel.com/docs/master/mraa/gpio_8h.html
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That makes a lot of sense, I should've seen that lol.
That's definitely what was wrong with it, I simply changed that line and voila. Thanks, Brian!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page