Go Down

Topic: avr/prgspace error problem (Read 2869 times) previous topic - next topic

GerryM

(I posted this on the wrong tpoic earlie)

I'm trying to use the MPU-6050 code from Jeff Rowberg in the FreeIMU library (MPU6050_raw.ino).  I've modified references from MPU6050 to MPU60X0 and included the SPI library in the sketch.  When I compile the sketch using arduino1.5.1r2 for an Arduino Mega2560 board, it works fine.  However when I compile the sketch for an Arduino Due, I get the following error:

fatal error: avr/prgspace.h: No such file or directory

Any help would be appreciated

Gerry

#1
Jan 20, 2013, 04:55 am Last Edit: Jan 20, 2013, 04:56 am by SomeRandomGuy Reason: 1
The issue here is that the earlier Arduino boards are all AVR chips, while the Due is now an ARM architecture. The Due does not use the prgspace.h file at all.

You will need to modify the library you are using in order to support the due.
First, open the library folder and go to the library's .cpp file. It might be called FreeIMU.cpp.

Look at the top for the avr/prgspace.h declaration. Then, you can try replacing that declaration with the following code.

Code: [Select]
#ifndef __arm__
#include <avr/pgmspace.h>
#else
#define PROGMEM /* empty */
#define pgm_read_byte(x) (*(x))
#define pgm_read_word(x) (*(x))
#define pgm_read_float(x) (*(x))
#endif


This may prove to be too involved, but I have had some success this way.

Good Luck!


GerryM

Many thanks for both comments. I'll try the suggestions.

Gerry

cam_

#4
Jan 30, 2013, 08:48 pm Last Edit: Jan 30, 2013, 08:53 pm by cam_ Reason: 1
I'm also experiencing the same issue. I'll admit I'm over my head here for the most part although I was able to successfully able to implement SomeRandomGuy's improvement to address some of the issues.

I also added "#define prog_uchar uint8_t" before the "#endif" to address the "error: invalid conversion from 'const char*' to 'const uint8_t*'" errors.

It now seems to compile however I am unable to establish I2C communications with the IMU and I2CScanner (http://playground.arduino.cc/Main/I2cScanner) is not recognizing it at all. Another user is also having this problem here http://arduino.cc/forum/index.php?topic=145697.0.

Have you had any luck?

EDIT: Oh, and I also commented out all the 'F' flags in the MPU6050_DMP6 sketch in the "Serial.println(F("example text"));" commands because of the error "error: 'PSTR' was not declared in this scope".

Hi,

i am also trying to make FreeIMU library work on the due.. with the above changes and some other minor tweaks i get the "raw" example running fine... calibration is another matter to be solved later since it seems to require eeprom...

i have another problem though.. in the FreeIMU.cpp the code does an update frequency calculation in the getQ function, i believe.. time is measured using the micros() function... this, however returns 0 in my case, so the frequency calculation returns a NaN (division by zero, of course)..

any suggestions why micros returns zero?

thnx,
  ales

OK.. Sorry. My mistake!

The original code used a custom invSqrt(x) function.. Replaced with 1.0/sqrt(x) and it works!

Cheers,
   Ales

barf

#7
Jan 31, 2013, 03:09 am Last Edit: Jan 31, 2013, 03:12 am by barf Reason: 1
Hi,

I had similar problems with the lack of avr/pgmspace.h in the MPU6050 code. Don't know if my fixes are legit by I basically just got rid of all uses of program space functions ( PROGMEM, pgm_read_byte(), prog_uchar, etc) and replaced them with regular memory assignments and access calls. I just wanted it to work. Performance was of secondary importance.

There are also several functions that take a parameter argument "useProgMem" where it appears to be a mechanism for not using pgmspace features. Unfortunately, the technique still fails if the entire header is unavailable. There are also few places that continue to use the pgmspace functions and ignore the "useProgMem" option.

There were a few other miscellaneous changes which I can't remember.

I had problems within the loop() code in the MPU6050_DMP6 example. Specifically, the first while-loop that checks the interupt & fifoCount would get stuck. Reading the comments, it seems the author anticipated this problem. I just changed it to:
Code: [Select]

 // wait for MPU interrupt or extra packet(s) available
 while (!mpuInterrupt && fifoCount < packetSize) {
   if (mpuInterrupt)
     break;


Not elegant but functional. After all the changes, my hacked version of the motion fusion example works great with my Sparkfun MPU9150 breakout (http://www.sparkfun.com/products/11486?) on my Arduino Due. (The unaltered code already worked fine with my Uno.)

Hope this helps,

-Rob

cam_

So nobody has had any issues communicating over I2C? I'm having trouble getting any response using the I2C scanner but everything works just peachy using my UNO with the same connections.

barf

#9
Feb 01, 2013, 10:32 pm Last Edit: Feb 01, 2013, 11:40 pm by barf Reason: 1
Nope, no problems with i2c. I used pins 20 and 21 for i2c and 7 for the interrupt.

cam_

Oh wow I feel retarded. I never even noticed there were two sets of I2C pins and was using the two by AREF and GND. Apparently the Due has two I2C interfaces.

Perhaps I should trade my Due back in haha, its obviously too smart for me.

I'll try that library for the MPU-6050 later this evening hopefully and let you all know if my hack job at porting it over was successful at all.

Thanks for your help!

cam_

Success! Has anyone else been able to get things running smoothly?

I'm curious about the range of values people are getting from their sensors. When using Jeff's MPU6050_DMP6 sketch with "#define OUTPUT_READABLE_WORLDACCEL" uncommented, what do your resting values trend to?

As I understand it, these should all approach zero after perhaps 30 seconds however I get a weird response from my z-axis. Its value hovers around 3500 when placed undisturbed on the table (positive z up). It appears to have some offset to it as it doesn't tend to zero when the orientation is changed such that z is parallel with the table surface.

Is this something others are also experiencing?

Go Up