Page 1 of 2

Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Sep 04, 2014 7:09 am
by Nakon
Hello,
First of all sorry for my English :roll:

I'm trying to build a simple arduino based head-tracker, basicly following this:

https://www.youtube.com/watch?v=QpO1Wty3F3I

https://github.com/mdjarv/arduinoheadtracker

And must be something I'm doing terribly bad, i think :?

I can see values like "1.23,14.39,-3.38" at the serial monitor (arduino IDE) changing very fast.
And if I move the sensor, these values change.

But when I run freepie code... nothing happens. :?:
Values at "Watch" are not changing at all.
All of them (yaw, pitch, roll, trackIR.yaw, ...) are always "0".

I checked Settings > Plugins > Free IMU and select COM port and baud rate.

Freepie code I use is:

Code: Select all

### CONFIGURATION ###

# Watch input and output values
DEBUG = True

# Output mode
OUTPUT_FREETRACK = False
OUTPUT_TRACKIR   = True

# Keybindings
KEY_CENTER = Key.Pause      # Center orientation to current position
KEY_TOGGLE_ON_OFF = Key.End # Toggle headtracking on or off

# Calibration multipliers
TRACKIR_MULTIPLIER   = 10
FREETRACK_MULTIPLIER = 0.001

### THE CODE ###

def update():
    global yaw
    yaw = freeImu.yaw
    global pitch
    pitch = freeImu.pitch
    global roll
    roll = freeImu.roll

def updateTrackIR():
    trackIR.yaw = (yaw - centerYaw) * TRACKIR_MULTIPLIER
    trackIR.pitch = (pitch - centerPitch) * TRACKIR_MULTIPLIER
    trackIR.roll = (roll - centerRoll) * TRACKIR_MULTIPLIER

    if DEBUG:
        diagnostics.watch(trackIR.yaw)
        diagnostics.watch(trackIR.pitch)
        diagnostics.watch(trackIR.roll)

def updateFreeTrack():
    freeTrack.yaw = (yaw - centerYaw) * -FREETRACK_MULTIPLIER # Inverted
    freeTrack.pitch = (pitch - centerPitch) * FREETRACK_MULTIPLIER
    freeTrack.roll = (roll - centerRoll) * FREETRACK_MULTIPLIER

    if DEBUG:
        diagnostics.watch(freeTrack.yaw)
        diagnostics.watch(freeTrack.pitch)
        diagnostics.watch(freeTrack.roll)

def center():
    global centerYaw
    centerYaw = yaw
    global centerPitch
    centerPitch = pitch
    global centerRoll
    centerRoll = roll

if starting: 
    enabled = True
    centerYaw = freeImu.yaw
    centerPitch = freeImu.pitch
    centerRoll = freeImu.roll
    
    global yaw
    yaw = 0.0
    global pitch
    pitch = 0.0
    global roll
    roll = 0.0
    freeImu.update += update

def do_update():
    if OUTPUT_FREETRACK:
        updateFreeTrack()
        
    if OUTPUT_TRACKIR:
        updateTrackIR()

if DEBUG:
    diagnostics.watch(yaw)
    diagnostics.watch(pitch)
    diagnostics.watch(roll)

if enabled:
    do_update()

if keyboard.getKeyDown(KEY_CENTER):
    center()
    
if keyboard.getPressed(KEY_TOGGLE_ON_OFF):
    enabled = not enabled
    center()
    do_update()
And Arduino sketch:

Code: Select all

#include <ADXL345.h>
#include <bma180.h>
#include <HMC58X3.h>
#include <ITG3200.h>
#include <MS561101BA.h>
#include <I2Cdev.h>
#include <MPU60X0.h>
#include <EEPROM.h>

//#define DEBUG
#include "DebugUtils.h"
#include "CommunicationUtils.h"
#include "FreeIMU.h"
#include <Wire.h>
#include <SPI.h>

float ypr[3]; // yaw pitch roll

// Set the FreeIMU object
FreeIMU my3IMU = FreeIMU();

void setup() { 
  Serial.begin(115200);
  Wire.begin();
  
  delay(5);
  my3IMU.init(); // the parameter enable or disable fast mode
  delay(5);
}

void loop() {
  my3IMU.getYawPitchRoll(ypr);
  Serial.print(ypr[0]);
  Serial.print(",");
  Serial.print(ypr[1]);
  Serial.print(",");
  Serial.println(ypr[2]);
  
  delay(10);
}

So, please, can anyone help me?
I'm completely lost :oops:

Regards!

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Sep 04, 2014 7:38 am
by CyberVillain
You cant have the serial monitor turned on in the Arduino IDE. Is it turned off?

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Sep 04, 2014 7:45 am
by Nakon
Yes, it's turned off.
Even IDE is closed.

Edit: I use Windows 7 64

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Sep 04, 2014 1:26 pm
by NeoTokyo_Nori
Not sure, but maybe there should be this line inside
if starting:

Code: Select all

    freeImu.update +=  do_update

Right now, all you have is this

Code: Select all

    freeImu.update += update
which is not calling debug.watch

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Sep 04, 2014 4:45 pm
by Nakon
Thank you for your interest.

I tried changing that line but then i have an error:

Code: Select all

name 'do_update' is not defined
Is there any simple example of reading serial port by FreePIE?
I think my problem is that way

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Fri Sep 05, 2014 12:20 am
by NeoTokyo_Nori
Nakon wrote:Thank you for your interest.
I tried changing that line but then i have an error:

Code: Select all

name 'do_update' is not defined
Is there any simple example of reading serial port by FreePIE?
I think my problem is that way
CyberVillan has made a generic serial com reader for us,
which I believe he is working on putting into the next update, right CV? ;)

In the meantime, I think you could try putting the
diagnostics.watch code inside def update():

Code: Select all

        
diagnostics.watch(trackIR.yaw)
        diagnostics.watch(trackIR.pitch)
        diagnostics.watch(trackIR.roll)

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Fri Sep 05, 2014 1:55 am
by CyberVillain
There is nothing wrong with the script. It calls update that reads the values of the IMU

ad then do_update from the main loop that updates freetrack or trackir

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Mon Sep 08, 2014 4:07 am
by Nakon
Thank you all.
It doesn't work yet.

As I see, the problem must be in the reading of serial COM.
I can see Arduino writing comma separated values at serial monitor.
But in FreePIE i'm getting nothing.
So... i'm doing wrong the reading of serial port, I think.
A generic serial com reader in FreePIE would be my medicine! :)
Regards!

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Tue Sep 09, 2014 12:55 am
by CyberVillain
I can see if I can add some debugging to the Com plugins (Ahrs, freeimu, generic). But i have very little time between work and family these days.

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Tue Sep 23, 2014 11:30 am
by NeoTokyo_Nori
Hi,
Just thought I should let you know,
I just managed to run the arduinoheadtracker code on my setup,
without making any changes to the code,
and it is giving the IMU data readings in the watch window, without any problems.

cheers

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Tue Sep 23, 2014 3:01 pm
by CyberVillain
You are using the ahrs plugin not the generic right?

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Tue Sep 23, 2014 3:10 pm
by NeoTokyo_Nori
CyberVillain wrote:You are using the ahrs plugin not the generic right?
Hi CV,
No, I was referring to the Free IMU code based on
https://github.com/mdjarv/arduinoheadtracker
and the IMU data was updating ok.

And, now I am testing it with the genericCom plugin,
to receive the FreeIMU data plus my gun button IO messages together.
So far, I am getting the messages coming through, but they are still very laggy.

So will have to work on eliminating the causes of lag.

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Tue Sep 23, 2014 3:35 pm
by CyberVillain
NeoTokyo_Nori wrote:
CyberVillain wrote:You are using the ahrs plugin not the generic right?
Hi CV,
No, I was referring to the Free IMU code based on
https://github.com/mdjarv/arduinoheadtracker
and the IMU data was updating ok.

And, now I am testing it with the genericCom plugin,
to receive the FreeIMU data plus my gun button IO messages together.
So far, I am getting the messages coming through, but they are still very laggy.

So will have to work on eliminating the causes of lag.
I think I will ahve to rewrite the code, I will load teh freeimu frimware onto my board and test

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Tue Nov 11, 2014 9:28 pm
by wilee98
ok I am using same code but cant get mine to work....

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Wed Nov 12, 2014 2:24 am
by Nakon
Do you mean my code or NeoTokyo's?

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Wed Nov 12, 2014 8:29 am
by wilee98
Either or would be fine, I can try both lol

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Wed Nov 12, 2014 9:08 am
by Nakon
I'm afraid i didn't make mine work.
Sorry.
I still can't read from serial.
A serial monitor tool in FreePIE would be a great help!

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Wed Nov 12, 2014 9:25 am
by wilee98
I can see changes in the arduino monitor just not in the freepie.

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Wed Nov 12, 2014 9:35 am
by Nakon
That's exactly what happens with mine.
I can see values comma separated changing very fast in Arduino's serial monitor but nothing happens in freepie.
Something i'm doing wrong, but have no idea what

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Wed Nov 12, 2014 9:54 am
by wilee98
Well as soon as I get it working or you, we can trade what we did lol

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Wed Nov 12, 2014 10:23 am
by Nakon
Of course! ;)

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Nov 13, 2014 3:37 am
by Nakon
A little (very little) step:

As i see at another post ;) i tried to simplyfy freepie script, running this simple code:

diagnostics.watch(freeImu.yaw)

Then, at watch window, i can see the value changes.
But only once. :?: (from starting value "0" to "25" for example)

If i run the script again, it does nothing :shock: (always "0")
Then i open Arduino monitor serial to confirm values are still there changing fast
And there are

If i run again freepie script, then i can see again yaw value changing only once at watch window
:shock: :?: :?

Am i having a synch problem?

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Nov 13, 2014 8:02 am
by CyberVillain
Please cut and paste the data from the serial monitor here

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Nov 13, 2014 5:09 pm
by wilee98
is this what ya want, I get this and it changes but no luck in freepie. I even tried just the one line and nothing. Don't know if we need to calibrate it or what, can't get anything to load to calibrate it. If need be I can get a video of what im doing right or wrong so I can get some help with this. It's killing me im wanting to play a game and can't.... LOL :cry: :cry: :cry: :cry:




Yaw: 152.56 Pitch: -44.05 Roll: -28.70
Yaw: 152.48 Pitch: -44.15 Roll: -28.66
Yaw: 152.42 Pitch: -44.22 Roll: -28.61
Yaw: 152.34 Pitch: -44.30 Roll: -28.58
Yaw: 152.27 Pitch: -44.38 Roll: -28.54
Yaw: 152.28 Pitch: -44.37 Roll: -28.49
Yaw: 152.28 Pitch: -44.37 Roll: -28.44
Yaw: 152.20 Pitch: -44.46 Roll: -28.40
Yaw: 152.21 Pitch: -44.44 Roll: -28.36
Yaw: 152.20 Pitch: -44.45 Roll: -28.30
Yaw: 152.15 Pitch: -44.51 Roll: -28.26
Yaw: 152.15 Pitch: -44.50 Roll: -28.22
Yaw: 152.08 Pitch: -44.59 Roll: -28.18
Yaw: 152.07 Pitch: -44.59 Roll: -28.13
Yaw: 152.00 Pitch: -44.68 Roll: -28.09
Yaw: 151.93 Pitch: -44.75 Roll: -28.05

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Fri Nov 14, 2014 2:20 am
by CyberVillain
You are sending the wrong format ;)

Change the output to send it like this

Code: Select all

152.56,-44.05,-28.70
You can check the Help for that plugin from FreePIE for more info
Load the FreeIMU_yaw_pitch_roll.pde example into the Arduino IDE. The FreePIE Free Imu plugin expects the format it receives to be comma separated (Yaw,Pitch,Roll). So we need to change the code to
my3IMU.getYawPitchRoll(ypr);

Serial.print(ypr[0]);
Serial.print(",");
Serial.print(ypr[1]);
Serial.print(",");
Serial.print(ypr[2]);
Serial.println("");

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Fri Nov 14, 2014 9:16 am
by wilee98
Thanks will try when I get home, I want to say I think one code I tried had commas but not sure lol. Will update when I can.

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Fri Nov 14, 2014 5:40 pm
by Nakon
CyberVillain, I use the "custom" skecth and have results like wilee's but without "Yaw" "Pitch" "Roll"
Only numbers comma-separated, like

1.23,14.39,-3.38
2.93,34.58,-4.57
1.52,17.37,-4.78
4.53,14.39,-3.56
8.83,31.39,-6.83

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Fri Nov 14, 2014 6:22 pm
by wilee98
no good here is both files I use


#include <ADXL345.h>
#include <bma180.h>
#include <HMC58X3.h>
#include <ITG3200.h>
#include <MS561101BA.h>
#include <I2Cdev.h>
#include <MPU60X0.h>
#include <EEPROM.h>

//#define DEBUG
#include "DebugUtils.h"
#include "CommunicationUtils.h"
#include "FreeIMU.h"
#include <Wire.h>
#include <SPI.h>

int raw_values[9];
//char str[512];
float ypr[3]; // yaw pitch roll
float val[9];

// Set the FreeIMU object
FreeIMU my3IMU = FreeIMU();

void setup() {
Serial.begin(115200);
Wire.begin();

delay(5);
my3IMU.init(); // the parameter enable or disable fast mode
delay(5);
}

void loop() {

my3IMU.getYawPitchRoll(ypr);
Serial.print(",");
Serial.print(ypr[0]);
Serial.print(",");
Serial.print(ypr[1]);
Serial.print(",");
Serial.print(ypr[2]);
Serial.println("");

delay(10);
}




And for Freepie

### CONFIGURATION ###

# Watch input and output values
DEBUG = True

# Output mode
OUTPUT_FREETRACK = False
OUTPUT_TRACKIR = True

# Keybindings
KEY_CENTER = Key.Pause # Center orientation to current position


# Calibration multipliers
TRACKIR_MULTIPLIER = 10
FREETRACK_MULTIPLIER = 0.001

### THE CODE ###

def update():
global yaw
yaw = freeImu.yaw
global pitch
pitch = freeImu.pitch
global roll
roll = freeImu.roll

def updateTrackIR():
trackIR.yaw = (yaw - centerYaw) * TRACKIR_MULTIPLIER
trackIR.pitch = (pitch - centerPitch) * TRACKIR_MULTIPLIER
trackIR.roll = (roll - centerRoll) * TRACKIR_MULTIPLIER

if DEBUG:
diagnostics.watch(trackIR.yaw)
diagnostics.watch(trackIR.pitch)
diagnostics.watch(trackIR.roll)

def updateFreeTrack():
freeTrack.yaw = (yaw - centerYaw) * -FREETRACK_MULTIPLIER # Inverted
freeTrack.pitch = (pitch - centerPitch) * FREETRACK_MULTIPLIER
freeTrack.roll = (roll - centerRoll) * FREETRACK_MULTIPLIER

if DEBUG:
diagnostics.watch(freeTrack.yaw)
diagnostics.watch(freeTrack.pitch)
diagnostics.watch(freeTrack.roll)

def center():
global centerYaw
centerYaw = yaw
global centerPitch
centerPitch = pitch
global centerRoll
centerRoll = roll

if starting:
enabled = True
centerYaw = freeImu.yaw
centerPitch = freeImu.pitch
centerRoll = freeImu.roll

global yaw
yaw = 0.0
global pitch
pitch = 0.0
global roll
roll = 0.0
freeImu.update += update

def do_update():
if OUTPUT_FREETRACK:
updateFreeTrack()

if OUTPUT_TRACKIR:
updateTrackIR()

if DEBUG:
diagnostics.watch(yaw)
diagnostics.watch(pitch)
diagnostics.watch(roll)

if enabled:
do_update()


Thanks again for any help

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Sat Nov 15, 2014 10:22 am
by CyberVillain
Very strange, only thing I can think of is that you use the wrong baudrate in FreePIE config

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Sun Nov 16, 2014 5:06 pm
by Nakon
Cybervillain, i checked baud rate several times.
115200 in arduino sketch and freepie settings

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Sun Nov 16, 2014 5:08 pm
by Nakon
wille, try this code in arduino:

Code: Select all

#include <ADXL345.h>
#include <bma180.h>
#include <HMC58X3.h>
#include <ITG3200.h>
#include <MS561101BA.h>
#include <I2Cdev.h>
#include <MPU60X0.h>
#include <EEPROM.h>

//#define DEBUG
#include "DebugUtils.h"
#include "CommunicationUtils.h"
#include "FreeIMU.h"
#include <Wire.h>
#include <SPI.h>

int raw_values[9];
//char str[512];
float ypr[3]; // yaw pitch roll
float val[9];

// Set the FreeIMU object
FreeIMU my3IMU = FreeIMU();

void setup() {
Serial.begin(115200);
Wire.begin();

delay(5);
my3IMU.init(); // the parameter enable or disable fast mode
delay(5);
}

void loop() { 

my3IMU.getYawPitchRoll(ypr);
Serial.print(ypr[0]);
Serial.print(",");
Serial.print(ypr[1]);
Serial.print(",");
Serial.print(ypr[2]);
Serial.println(""); 

delay(10);
}

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Mon Nov 17, 2014 2:00 am
by CyberVillain
You must be doing something wrong sorry, thats all I can say :/
FreeIMU uses strings and the format you show is correct. So it's nothing wrong on the contract

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Mon Nov 17, 2014 7:01 am
by Nakon
Yes.
I know i'm doing something wrong :? ;)
But i don't know what :oops:

Well.
This project has two sides: Arduino and freepie.
I think i can say that Arduino side is OK (i can write values to serial at the correct format)
COM port is 12 and its baud rate is 115200

At the other side, Freepie.
I set FreeIMU settings (COM 12, 115200 baud rate)
And use this simple script for testing:

Code: Select all

diagnostics.watch(freeImu.yaw)
Nothing more! (no "if starting", no "update",...)

I'm considering upload a little vid to youtube showing what i do :idea:
That way maybe you can see what i'm doing wrong :?:
What do you think?

Regards!

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Mon Nov 17, 2014 9:52 am
by CyberVillain
I do not think that will help alot, sorry. I can try loading the FreeIMU software onto my board. But since its string noly I cant really see what going, I can fix a version for you with some debug (Of FreePIE i mean)

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Mon Nov 17, 2014 9:57 am
by Nakon
I really appreciate that freepie versiĆ³n with debug!!!
Thanks!

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Mon Nov 17, 2014 12:30 pm
by CyberVillain
Tried with this FreeIMU version https://github.com/Fabio-Varesano-Association/freeimu and this code

Code: Select all

#include <ADXL345.h>
#include <bma180.h>
#include <HMC58X3.h>
#include <ITG3200.h>
#include <MS561101BA.h>
#include <I2Cdev.h>
#include <MPU60X0.h>
#include <EEPROM.h>

//#define DEBUG
#include "DebugUtils.h"
#include "CommunicationUtils.h"
#include "FreeIMU.h"
#include <Wire.h>
#include <SPI.h>

int raw_values[9];
//char str[512];
float ypr[3]; // yaw pitch roll
float val[9];

// Set the FreeIMU object
FreeIMU my3IMU = FreeIMU();

void setup() {
  Serial.begin(115200);
  Wire.begin();
  
  delay(5);
  my3IMU.init(); // the parameter enable or disable fast mode
  delay(5);
}

void loop() { 
  
  my3IMU.getYawPitchRoll(ypr);
  Serial.print(ypr[0]);
  Serial.print(",");
  Serial.print(ypr[1]);
  Serial.print(",");
  Serial.print(ypr[2]);
  Serial.println(""); 
  
  delay(10);
}

At 115200 baud, and it works

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Nov 20, 2014 10:29 am
by Nakon
What Arduino board are you using? I'm using a Leonardo (Pro-Micro)
And what sensor? I use a GY-85

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Nov 20, 2014 10:49 am
by wilee98
Same I think, my micro is red 5v version.

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Nov 20, 2014 11:09 am
by wilee98
Can you get any of the processing to work ie 3d cube, all the sketches I have found give errors so I can run any of them. I think we might have a hardware problem.

Re: Help needed: Arduino > FreePIE (can't read serial)

Posted: Thu Nov 20, 2014 11:22 pm
by wilee98
ok something I noticed, my numbers in the serial reader don't really stay in one place they constantly move, and don't change when rotated. I thank we are having a conflict between our gyro and accel files. I did find a arduino file that did work but it's not in the right format IE. y,r,p... But can't change it either, or can't figure out how too, plus uses different other files and no freeimu. That's the conclusion I have, I feel we both need to buy a different 9dof board, which I think i'm gonna do cause this is giving me a headache LOL.