EV3 C-code for third party devices (I2C)

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 C-code for third party devices (I2C)

Post by HaWe »

thank you Lauro for your efforts!

if(ButtonWaitForAnyPress(TITLE_DELAY) == BUTTON_ID_ESCAPE)

is actually not what I intended to do, I wanted to check if any button has been hit incidentally without any delay for the rest of the program loop, and just return if it happened or not.
I hope that maybe someone will find out some day what's wrong with my use of checkButtons().


I now again altered your program and attached the gyro to S4.

Code: Select all

#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ioctl.h>

#include "lms2012.h"
#include "ev3_button.h"
#include "ev3_lcd.h"

//Runtime constants
const int MAX_SAMPLES = 1000;

//Global variables and constants used by the sensor handling functions

#define TITLE_DELAY 1000

IIC *pXgl;

//***************************************************************************************
// Microinfinity XG1300L IMU settings

const char XGL_PORT = 0x3;       // The ports are designated as XGL_PORT_NUMBER-1

const int  XGL_PACKET_SIZE = 10; // 2(gyyro angle)+2(gyro rate)+2(acc x)+2(acc y)+2(acc z)
int        xgl_device_file;
//***************************************************************************************



int init_xg1300l_gyro()
{
//...
If I want to attach 3 NXT_US-sensors at S1,S2,and S3 and want to show the values on the screen as well, how would the program look like?
(I know there might be an issue concerning sonic reflection noise, but that can be possibly handled by one or two steps after^^)
lvoc
Posts: 38
Joined: 10 Sep 2013, 13:34

Re: EV3 C-code for third party devices (I2C)

Post by lvoc »

I don't know why the checkButtons function does not work. However, I looked at the kernel modules that handle the buttons and LEDs, and noticed that using this hardware is not very complex. It is possible to have an operation as the one you need . I wrote some code that you could use as reference for your program.
http://www.robotnav.com/buttons-and-leds/
Last edited by lvoc on 20 Nov 2013, 15:14, edited 1 time in total.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 C-code for third party devices (I2C)

Post by HaWe »

thank you,
that would mean one wouldn't have to both #include ev3_buttons.h and don't have to add ev3_button.c to the .prj any more, correct?

now back to my last/next question:
If I want to attach 3 NXT_US-sensors at S1,S2,and S3 and want to show the values on the screen as well, how would the program look like?
they are IIC devices/files too, so that's why I'm asking in this thread about 3rd party devices
Last edited by HaWe on 11 Nov 2013, 18:28, edited 1 time in total.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 C-code for third party devices (I2C)

Post by HaWe »

and I still get this effing error if I try to compile your program:

make: *** No rule to make target `lms2012.o', needed by `all'. Stop.


instead, if I compile a file without #including lms2012.h like, e.g. http://sourceforge.net/apps/phpbb/mindb ... 562#p17550 everything is ok.

I already resetted the makefile template to default, but always the same "lms2012.o rule error" !
lvoc
Posts: 38
Joined: 10 Sep 2013, 13:34

Re: EV3 C-code for third party devices (I2C)

Post by lvoc »

I have limited experience with Bricxcc, and I am not quite sure why you get the 'lms2012.o' error. A couple of days ago, I used Bricxcc to compiled a program that uses several program files (.cpp or .c) and include files (.h). When you specify the project files, you should only add the include files (.h). I wrote a short explanation (with screenshots) showing the steps I followed at:
http://www.robotnav.com/position_and_control/ (see Windows section)

About your question on using several IIC devices at the time. The program that you have, should be ready to read from the other ports. When you open a IIC device, you have access to any sensor that uses this interface. Since the other ports (sonar) don't need any special configuration you only need to read them. As far as I can tell, you should be getting ranges from the sonars using something like:

sonar_range_on_port_number_1 = pXgl->Raw[0][pXgl->Actual[0][0];
sonar_range_on_port_number_2 = pXgl->Raw[1][pXgl->Actual[1][0];
sonar_range_on_port_number_3 = pXgl->Raw[2][pXgl->Actual[2][0];
gyroscope_angle_on_port_number_4 = pXgl->Raw[3][pXgl->Actual[3]][0]*256+pXgl->Raw[3][pXgl->Actual[3]][1];
Last edited by lvoc on 20 Nov 2013, 15:14, edited 2 times in total.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 C-code for third party devices (I2C)

Post by HaWe »

thank you Lauro, but I'm using just your original code which you provided and of course there is no other #include than those you have written.
Nevertheless there's this stupid makefile error.
I am totally appalled because I can't go on and try anything and have no idea at all about how this issue could be cleared.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 C-code for third party devices (I2C)

Post by HaWe »

I think the thing which has to be done to work with BCC is
- completely drop the lms2012.h plus the 2 appending files
- use JH's original lcd and button lib and anything
- write a basic library ( just "ev3_sensors.h", no additional .c files and all that ) providing sensor API functions which work with your low level code as a substitute for the lms2012 stuff.

Having this I would be glad to contribute by writing some wraps for a convenient medium-level user-interface
like, e.g.

Code: Select all

SetSensor(port, PinType) // UART, IIC, ADC1, ADC6 (, ...)

ReadSensor (port, int32 &values[] (, numberofvalues) (,SensorTypeMode) ) // 
But first of all this makefile crap has to be fixed.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 C-code for third party devices (I2C)

Post by HaWe »

no idea anybody how to fix this error
make: *** No rule to make target `lms2012.o', needed by `all'. Stop.


I would not like to abandon this C thing completely just because the f***ing makefile or linker or whatever makes muck.
lvoc
Posts: 38
Joined: 10 Sep 2013, 13:34

Re: EV3 C-code for third party devices (I2C)

Post by lvoc »

Could you write a list of the files that you are including in your project?
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: EV3 C-code for third party devices (I2C)

Post by HaWe »

do you mean: the .c files added by the project manager?
Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests