Arduino and Freepie ?
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Arduino and Freepie ?
Hi, I would like to use arduino with Freepie in my project,
(to send imu data along with button IO events over bluetooth)
But to my surprise I have not seen anything that mentions arduino in the Freepie documents or forums.
Am I just missing something? or is arduino not implemented (yet)
If not, is there still a way to do it? (with UDP packets or something)
cheers!
(to send imu data along with button IO events over bluetooth)
But to my surprise I have not seen anything that mentions arduino in the Freepie documents or forums.
Am I just missing something? or is arduino not implemented (yet)
If not, is there still a way to do it? (with UDP packets or something)
cheers!
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
We dont have any raw Arduino data plugin. Only specific Arduino library implementations. Namly ahrs and FreeIMu
If you dont want to roll your own plugin you can read the data off the serial port using python (The scripting language of FreePIE)
http://playground.arduino.cc/interfacing/python
If you dont want to roll your own plugin you can read the data off the serial port using python (The scripting language of FreePIE)
http://playground.arduino.cc/interfacing/python
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
btw, the easisest way is probaly to use .NET's own serial port client
From the script do
Now you can access the SerialPort class, here is the doc for it
http://msdn.microsoft.com/en-us/library ... .110).aspx
From the script do
Code: Select all
from System.IO.Ports import SerialPort
http://msdn.microsoft.com/en-us/library ... .110).aspx
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Thanks CyberVillan
So, it looks like reading the data off the serial port using python, is the way to go for now..
I do not have the skills to write a plugin at this point in time,
but hope a plugin can be worked on since arduino has so many potential applications,
and I will contribute what I can in the event that it does happen!
cheers!
So, it looks like reading the data off the serial port using python, is the way to go for now..
I do not have the skills to write a plugin at this point in time,
but hope a plugin can be worked on since arduino has so many potential applications,
and I will contribute what I can in the event that it does happen!
cheers!
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
A general arduino plugin would just be a generic Serial plugin I guess that pretty muchs wraps the SerialPort anyway
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
So are you saying that it would be easy for me/someone to do?
Or that it would be easy for you to do??? wink wink ; )
Or that it would be easy for you to do??? wink wink ; )
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
No, im just saying that a generic Serial port plugin built into FreePIE wont be much easier than using the SerialPort class directly from python.
Give it a try, write a string on your Arduino's serial port and try fething it in FreePIE using the code I gave you below
Give it a try, write a string on your Arduino's serial port and try fething it in FreePIE using the code I gave you below
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Ok, I will look into it.
But I should give warning that I have no experience with .net.
and also kind of allergic to C variants : /
Anyway, to make sure that I understand you:
Should I put this code inside the FREEPIE script ?
.NET's own serial port client
But I should give warning that I have no experience with .net.
and also kind of allergic to C variants : /
Anyway, to make sure that I understand you:
Should I put this code inside the FREEPIE script ?
.NET's own serial port client
Code: Select all
from System.IO.Ports import SerialPort
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
Yes, thats the syntax to import modules in Python
Once that is done you can create a serial port instance like this
Once that is done you can create a serial port instance like this
Code: Select all
if starting:
port = SerialPort("com1", 57600)
port.Open()
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Hi, I put that code in the freepie script,
and it runs without error for the first time,
but the next time the same comport cannot be accessed,
so the port probably has to be closed when ending right?
I tried this but did not work.
I was also surprised to find that
if starting:
is not defined in the the python language, or in the freepie reference,
so some documentation may be needed for it too?
BTW, I am wondering if this pySerial library would make things easier.
http://playground.arduino.cc/interfacing/python
cheers!
and it runs without error for the first time,
but the next time the same comport cannot be accessed,
so the port probably has to be closed when ending right?
I tried this but did not work.
Code: Select all
if ending:
port.Close()
if starting:
is not defined in the the python language, or in the freepie reference,
so some documentation may be needed for it too?
BTW, I am wondering if this pySerial library would make things easier.
http://playground.arduino.cc/interfacing/python
cheers!
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
Yeah, i know neither the starting or stopping booleans are in the code completion. Its on my list
So change to if stopping
So change to if stopping
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Wow, it really is a festival over on reddit isn`t it
I doubt there has ever been a product in history like oculus where people are just throwing money at their screens and demanding they have it now! It`s probably more so than the iphone was.
I am not expecting my notification for a couple of days, but it`s pretty hard to NOT keep checking all the things
Anyway to get back on topic:
I have run into the problem that the same port that arduino is using to send the serial data
cannot be opened from freepie at the same time, so I obviously I cannot read the serial data from arduino, doh!
This is the code I am testing it with so far.
Looks like that`s as far as I get for tonight!
I doubt there has ever been a product in history like oculus where people are just throwing money at their screens and demanding they have it now! It`s probably more so than the iphone was.
I am not expecting my notification for a couple of days, but it`s pretty hard to NOT keep checking all the things
Anyway to get back on topic:
I have run into the problem that the same port that arduino is using to send the serial data
cannot be opened from freepie at the same time, so I obviously I cannot read the serial data from arduino, doh!
This is the code I am testing it with so far.
Code: Select all
def readSerialPort():
serialInputLine = port.ReadLine()
def closeSerialPort():
port.Close()
if starting:
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 2
global port
port = SerialPort("com18", 115200)
port.Open()
port.DataReceived += readSerialPort
port.ErrorReceived += closeSerialPort
Looks like that`s as far as I get for tonight!
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
Do you close any other program thats reading from the port like the Arduino IDE
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Ha! you were right, closing the Arduino IDE solved it!
I would have never thought of doing that myself, so thanks.
diagnostics.watch(port.ReadLine)
is only giving something like
ironPython.runtime..
for now..
I would have never thought of doing that myself, so thanks.
diagnostics.watch(port.ReadLine)
is only giving something like
ironPython.runtime..
for now..
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
Hmm, ReadLine will halt the script thread which will make FreePIE angry. Cant you read it async instead?
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Hi there,
Yeah, I wasn`t getting anything so far with that, so I was wondering what to do next...
But I don`t see anything in the .net page about async.
Can you elaborate further?
edit: may be use SerialPort::ReadTo Method?
Yeah, I wasn`t getting anything so far with that, so I was wondering what to do next...
But I don`t see anything in the .net page about async.
Can you elaborate further?
edit: may be use SerialPort::ReadTo Method?
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Do I need to use the
SerialDataReceivedEventHandler ?
I really don`t understand C++ code very well
SerialDataReceivedEventHandler ?
I really don`t understand C++ code very well
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
Code: Select all
from System.IO.Ports import SerialPort
def update(s, e):
global port
indata = port.ReadExisting();
diagnostics.watch(indata)
if starting:
port = SerialPort("COM1")
port.DataReceived += update
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Hi, I tried to get that working here, but I see nothing so far
Just curious, what arguments is update expecting?
Note:
I should be getting constant Ping data from an ultrasonic sensor on that serial port.
I can see the live serial data on the serial monitor in arduino IDE. like this
Ping: 4cm
Ping: 4cm
Ping: 4cm
Ping: 4cm
Ping: 5cm
Ping: 5cm
Ping: 5cm
Ping: 5cm
Code: Select all
from System.IO.Ports import SerialPort
def update(s, e):
global port
indata = port.ReadExisting()
diagnostics.watch(indata)
diagnostics.debug(indata)
if starting:
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 2
port = SerialPort("com18", 115200)
port.Open()
port.DataReceived += update
Code: Select all
def update(s, e):
I should be getting constant Ping data from an ultrasonic sensor on that serial port.
I can see the live serial data on the serial monitor in arduino IDE. like this
Ping: 4cm
Ping: 4cm
Ping: 4cm
Ping: 4cm
Ping: 5cm
Ping: 5cm
Ping: 5cm
Ping: 5cm
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
I think its better to listen to the event before doing open, try that.. But probaly wont help..
Will have to dig out my ardunio and test, sorry
Will have to dig out my ardunio and test, sorry
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Ok, thanks anyway! I will keep trying.
By the way, are you planing to make the DK2 position data (x,y,z) accessible in freepie??
We gotta get it right??
By the way, are you planing to make the DK2 position data (x,y,z) accessible in freepie??
We gotta get it right??
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
It works for me.. Be very carefull though, since the update function is executing outside of the FreePIE sandbox it will hard crash if you do something wrong in that function, so always save script before running so you do not lose work
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Hello!
I had to spend most of the week dealing with some other arduino related issues,
but I still have not been able to get serial data to show up in freepie.
I got the Razor IMU working, so am trying to get data from that!
I had to spend most of the week dealing with some other arduino related issues,
but I still have not been able to get serial data to show up in freepie.
I got the Razor IMU working, so am trying to get data from that!
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
But the Razor IMU supports AHRS so you should use the AHRS plugin instead
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Hi!
As I mentioned in the "Sparkfun Razor IMU - Freepie script" thread,
I have the AHRS IMU data working and showing data in freepie,
So I just need the same serial data to show, using the serial port method in this thread.
But it just will not work for me!
I am using COM19, 57600
and this is working fine
But this still gives me nothing, no error message, no data, nothing
if I use port.Open(), it crashes...
Would it just be simpler for you to modify AhrsImuPlugin to parse generic serial data?
As I mentioned in the "Sparkfun Razor IMU - Freepie script" thread,
I have the AHRS IMU data working and showing data in freepie,
So I just need the same serial data to show, using the serial port method in this thread.
But it just will not work for me!
I am using COM19, 57600
and this is working fine
Code: Select all
def update():
diagnostics.watch(ahrsImu.yaw)
if starting:
ahrsImu.update += update
Code: Select all
from System.IO.Ports import SerialPort
def update():
#def update(s, e):
diagnostics.debug("serial data received")
# indata = port.ReadExisting();
# diagnostics.debug(indata)
if starting:
global port
port = SerialPort("COM19", 57600)
# port.Open()
port.DataReceived += update
Would it just be simpler for you to modify AhrsImuPlugin to parse generic serial data?
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
I wipped up something for you to test
Try
For byte data
And for text
Try
Code: Select all
for buffer in genericCom.ReadExisting():
diagnostics.watch(buffer)
And for text
Code: Select all
for text in genericCom.ReadExistingString():
diagnostics.watch(text)
You do not have the required permissions to view the files attached to this post.
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Hi cybervillan, thanks!
but you may be going a bit to fast for me...
what should I do with FreePIE.Core.Plugins.dll that you attached
I have tried this with your code
so far I get no errors, but still no data in the watch window...
but you may be going a bit to fast for me...
what should I do with FreePIE.Core.Plugins.dll that you attached
I have tried this with your code
Code: Select all
from System.IO.Ports import SerialPort
def update(s, e):
for buffer in genericCom.ReadExisting():
diagnostics.watch(buffer)
for text in genericCom.ReadExistingString():
diagnostics.watch(text)
if starting:
global port
port = SerialPort("COM19", 9600)
# port = SerialPort("COM19", 57600)
port.DataReceived += update
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
Have you replaced the dll in the plugins folder of FreePIE?
The correct usage is
Tou cant combine ReadExstingStreing and ReadExsting
The correct usage is
Code: Select all
def update():
for text in genericCom.ReadExistingString():
diagnostics.watch(text)
if starting:
genericCom.update+= update
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
WOW!! YES!!!
It is working finally
You must be a genius cybervillan
I am not sure if this is something to be concerned about,
but here is what the text looks like in the console window.
Just wondering if those line breaks should be there...
It is working finally
You must be a genius cybervillan
I am not sure if this is something to be concerned about,
but here is what the text looks like in the console window.
Just wondering if those line breaks should be there...
Code: Select all
#YPR=-169.93,-2.7
9,-9.27
#YPR=-169.94,-2.80,-9.26
#YPR=-1
69.94,-2.79,-9.27
#YPR=-169.94,-2.77,-9.
28
#
YPR=-169.95,-2.74,-9.31
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
Since its generic it wont read until new line. It will read until the next time the script will ask for data.
diagnsotics.debug will add a line
If you want to read a line then you need to ReadExistingString until you find a new line
diagnsotics.debug will add a line
If you want to read a line then you need to ReadExistingString until you find a new line
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Hi,
just to clarify, this is the code I was using to get the above output
just to clarify, this is the code I was using to get the above output
Code: Select all
def update():
for text in genericCom.ReadExistingString():
diagnostics.watch(text)
diagnostics.debug(text)
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
I updated the plugin with a ReadLine function to make it easier, see attached
Code: Select all
def update():
line = genericCom.ReadLine()
if line != "":
diagnostics.debug(line)
if starting:
genericCom.update += update
You do not have the required permissions to view the files attached to this post.
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Yes!, the output looks beautiful
#YPR=-169.94,-1.54,-7.30
#YPR=-169.94,-1.55,-7.29
#YPR=-169.94,-1.56,-7.28
#YPR=-169.94,-1.55,-7.31
#YPR=-169.94,-1.54,-7.34
#YPR=-169.94,-1.57,-7.37
#YPR=-169.95,-1.56,-7.39
#YPR=-169.94,-1.55,-7.34
#YPR=-169.94,-1.57,-7.33
#YPR=-169.95,-1.60,-7.34
#YPR=-169.95,-1.55,-7.33
#YPR=-169.94,-1.54,-7.30
#YPR=-169.94,-1.55,-7.29
#YPR=-169.94,-1.56,-7.28
#YPR=-169.94,-1.55,-7.31
#YPR=-169.94,-1.54,-7.34
#YPR=-169.94,-1.57,-7.37
#YPR=-169.95,-1.56,-7.39
#YPR=-169.94,-1.55,-7.34
#YPR=-169.94,-1.57,-7.33
#YPR=-169.95,-1.60,-7.34
#YPR=-169.95,-1.55,-7.33
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Hello CV, The serial data is flowing smooth !
I am glad we now have a new plugin feature for the next version update
Now, I have to get busy working on the arduino side of things to make all my buttons and sensors to work.
The next step is,
I need to connect at least 2 arduino AHRS IMUs to the pc at the same time, while using the generic serial to send button IO events.
Connection is serial over bluetooth, so com40 and com41 will be used at the same time (for example).
And we would like to have
genericCom[0].update += update
genericCom[1].update += update
I guess the IMU data will have to be handled by the genericCom now
in order to handle the IMU data plus button IO data at the same time...?
(note: the IMUs have to be on separate bluetooth connections, in my case )
I can imagine that people will want to connect several IMUs simultaneously
for things like arms/upper body/full body tracking, so this can have broader applications for freepie users.
I know that the wiimote plugin can handle 2 or more wiimotes.
I am wondering, do you think it is possible to do the same with the serial com
I am glad we now have a new plugin feature for the next version update
Now, I have to get busy working on the arduino side of things to make all my buttons and sensors to work.
The next step is,
I need to connect at least 2 arduino AHRS IMUs to the pc at the same time, while using the generic serial to send button IO events.
Connection is serial over bluetooth, so com40 and com41 will be used at the same time (for example).
And we would like to have
genericCom[0].update += update
genericCom[1].update += update
I guess the IMU data will have to be handled by the genericCom now
in order to handle the IMU data plus button IO data at the same time...?
(note: the IMUs have to be on separate bluetooth connections, in my case )
I can imagine that people will want to connect several IMUs simultaneously
for things like arms/upper body/full body tracking, so this can have broader applications for freepie users.
I know that the wiimote plugin can handle 2 or more wiimotes.
I am wondering, do you think it is possible to do the same with the serial com
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
Yeah, its been on my list. I guess I have to remove the settings and let you create a port from code like
Code: Select all
deviceZero = genericCom.create(0, 57600)
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
That woiuld be awesome CVCyberVillain wrote:Yeah, its been on my list. I guess I have to remove the settings and let you create a port from code likeCode: Select all
deviceZero = genericCom.create(0, 57600)
So we can put multiple coms and DK2 position data
as upcomming features in the next update
These are Exciting times
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Hello CV, how is it going?
I have not been able to figure out the correct usage for sending keyboard commands.
The reference page gives this:
setKeyDown void setKeyDown (Key key)
But all I get so far are errors, and crashes,
Do I have to import the keyboard class or something
I have not been able to figure out the correct usage for sending keyboard commands.
The reference page gives this:
setKeyDown void setKeyDown (Key key)
But all I get so far are errors, and crashes,
Code: Select all
def update():
serialMsg = genericCom.ReadLine()
if serialMsg != "":
# if serialMsg == "WASD":
keyboard.setKeyDown(Key w)
-
- Petrif-Eyed
- Posts: 2166
- Joined: Mon Jun 22, 2009 8:36 am
- Location: Stockholm, Sweden
Re: Arduino and Freepie ?
The correct usage is
Code: Select all
keyboard.setKeyDown(Key.W)
-
- Cross Eyed!
- Posts: 144
- Joined: Wed Jul 16, 2014 10:29 am
- Location: Tokyo, Japan
Re: Arduino and Freepie ?
Hi CV,
Something strange is happening...
The serial com part works alright, and serial messages are showing ok.
But just adding that one line (even when commented out!) give these errors:
object reference is not set to object instance.
item with same key has already been added.
(the error message are in japanese, so the translation may be a little off)
If I take off the comment, it gives the same errors, or crashes freepie
I have been stuck in the same spot...
Something strange is happening...
The serial com part works alright, and serial messages are showing ok.
Code: Select all
def debugger():
serialMsg = genericCom.ReadLine()
if serialMsg != "":
diagnostics.debug(serialMsg)
diagnostics.watch(serialMsg)
object reference is not set to object instance.
item with same key has already been added.
(the error message are in japanese, so the translation may be a little off)
Code: Select all
def debugger():
serialMsg = genericCom.ReadLine()
if serialMsg != "":
diagnostics.debug(serialMsg)
diagnostics.watch(serialMsg)
# keyboard.setKeyDown(Key.W)
I have been stuck in the same spot...