Omnimaga
Calculator Community => TI Calculators => Lua => Topic started by: Jim Bauwens on July 14, 2011, 04:29:29 pm
-
Recently I got on the idea that the Lua print command in Nspire Lua might print to the serial console. To test this, I built a max232 TTL converter and hooked my nspire to my laptop. And yes, it printed to the serial console!
Then I ordered an Arduino Uno, with the idea to hook it up to my nspire and control stuff.
A few days ago I received it and I started working. I had some problems until today because the the voltage on serial port of the arduino was to high for my nspire, and caused a reset everytime I connected it. Today I discovered (with the help of Kerm and benryves) that its only does that when its getting its power through usb, and not the power connector. So I switched to another power supply and all was fine :)
The print command in Nspire has some limitations though, you can only send bytes with data 1 to 127, and its also not the only data that gets send to the serial port. To overcome these problems, I made a little simple protocol to talk with my arduino. A sample data packet (in ascii) looks like this:
nomOKOCEHONOKOFOOOO@BDFON\r\n
"nom" defines the start of a data packets, and "\r\n" the end (it gets automatic added with print). 2 chars represent one byte that has been split in two (to be able to send 0-255).
My first real world example is controlling a little led display through my nspire. The arduino here just acts as a "proxy" to send the data to the display.
(http://bwns.be/jim/luaserial1.jpg)
(http://bwns.be/jim/luaserial2.jpg)
Sadly though I can send data (yet) from the arduino to my nspire, but if I do some work on reverse engineering the other dock connector pins, I think I'll be able to find a solution.
Edit:
-
Wow, that's awesome, Jim. Great job. :D
-
Wow just wow. This deserves a news. It is great news for nspire development.
-
Thanks both :)
I thinks it pretty cool because people can do really cool things with it :D
-
Oh yeah and we don't even need C for this. I'm just amazed at the wonders this community can do
-
this is good stuff, this is realy wonderful, I'm looking forward to some amazing things being done around this...
-
Great job Jim ;) I'd love a video :)
-
We need to start our nspire controlled robot army lol
I agree with ephan could we see a video? What do you think you'll be able to do with this?
-
I'll try to make a video as soon as possible :)
What do you think you'll be able to do with this?
Well, with the led display I just can display some text, kinda limited. But I can hook other things up to my arduino (an lcd for example) that can do much more. You could make little robots with it, but you just have the problem that you can't send anything back to the nspire. I'm trying to find a solution for this now.
-
Well, that's awesome Jim :D
-
Nice idea jim :)
-
Thanks :)
I added a video to the top post. Its not the most clear one though, but you should get the idea :)
-
Hook a better LCD up to the older Nspires. :D
-
I might try to control a AV display, as other people have done that already with an arduino.
-
nice. I hope you figure out the input soon. Good luck
-
Really good job.
-
Answer to Netham45:
The stuff that took so long to type was: 'while 1 do led("I") sleep(1) led("<3") sleep(1) led("Omnimaga") sleep(3) end'.
Its not the most easy thing to do while filming the whole thing, and typing with one hand ;)
-
Holy cow!
Amazing, Jim! :D
-
In case anyone wants it, you can find the Lua and the C (for the arduino) source code here: http://bwns.be/jim/arduino-ti.zip
-
In case anyone wants it, you can find the Lua and the C (for the arduino) source code here: http://bwns.be/jim/arduino-ti.zip
Arduino takes Processing as code :P Not C? Or can it also take C? I'm pretty sure it's Processing though.
-
Well, its Processing, but I think its valid C anyway :p
-
Well, its Processing, but I think its valid C anyway :p
It's Processing then, and save it as .pde, not as .c :P
-
This is a bit off topic, but if you can control external hardware, can you also control external files on the calculator?
-
If you mean files on the local calculator, you can access libraries with Lua.
If you mean something like an sdcard, no, because we can't get yet hardware input .
There is though a chance that you can connect an sdcard to the dock, but more research has to be done on it.
-
I meant can you get data from other lua files on the local calculator (i.e. level data, high scores, etc.)?
-
I know I'm a bit late, but wow. That video is epic. :D
-
Thanks :D
-
I meant can you get data from other lua files on the local calculator (i.e. level data, high scores, etc.)?
Not really, the data has to be in the same .tns file, and then get retrieved with var.recall (http://wiki.inspired-lua.org/var.recall), which grabs a Maths activity variable and puts in in a Lua variable
-
Adriweb, you can also use math.eval to execute a function in a library document (not in the current tns file) and return stuff saved there.
-
yep, but I think that if you have a lot of calculations to do, importing the variables in Lua then do all your calculations within lua (and then var.store() the final result) is much faster than doing all the calculations in a math.eval() call, as it's calling the math 'server' (as they call it) everytime ...
EDIT : but I think it's fine if you have only a few calculations to make
-
Yeah, that is very true :)
-
That looks great, I wish I was as skilled with external hardware, as it looks to be quite interesting! :D
-
Thanks apcalc :)
-
jimbauwens, may be you would be interested by a native Lua extension for this, without the original print() limitations?
-
ExtendeD, you don't know how much I was researching after I heard the news :D
The thing is with the file functions in os.h I can read/write to the serial port (uber awesome). But when reading stdin, it will block until there is data.
And since I can not check if there is data some way, I can't use this method.
There are two possibilities for me:
1) Directly talk to the serial hardware
2) Make stdin non blocking
2 can be done with fcntl() (from fcntl.h), and since it's a posix function it might be in the Nspire. But finding it is another task ^^.
If you have suggestions, please post them :D
-
You should try low-level serial port access, it shouldn't be too difficult.
-
Okay, I'll look at that.
But I have another question: is the method of reading the serial port the same on CX and classic?
(Since they use other uart hardware)
-
No, they use different registers.
-
Okay, thanks for the information.
When I got some time I'll try to use this method.
-
Sound via Ndless is possible, right?
-
Yes, it is :)
And now we can create modules that make it possible in Lua (and even better quality!) :)
-
Ok that's good to hear then. I wonder, since the processor is 150 MHz, if you could have sound as complex as this?
Or even midi-based sound like in Doom?
-
Maybe, but I'm not sure.
Right now I don't have time to make a player, but if no one else does it, I'll make one.