Author Topic: Controlling external hardware through Lua  (Read 19395 times)

0 Members and 2 Guests are viewing this topic.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Controlling external hardware through Lua
« 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:
Code: [Select]
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.






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:
« Last Edit: July 15, 2011, 06:05:53 am by jimbauwens »

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Controlling external hardware through Lua
« Reply #1 on: July 14, 2011, 04:33:40 pm »
Wow, that's awesome, Jim.  Great job. :D

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: Controlling external hardware through Lua
« Reply #2 on: July 14, 2011, 04:57:39 pm »
Wow just wow. This deserves a news. It is great news for nspire development.
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Controlling external hardware through Lua
« Reply #3 on: July 14, 2011, 05:00:28 pm »
Thanks both :)

I thinks it pretty cool because people can do really cool things with it :D

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: Controlling external hardware through Lua
« Reply #4 on: July 14, 2011, 05:08:22 pm »
Oh yeah and we don't even need C for this. I'm just amazed at the wonders this community can do
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline renatose

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 209
  • Rating: +4/-0
  • watch out the power balls
    • View Profile
Re: Controlling external hardware through Lua
« Reply #5 on: July 14, 2011, 05:17:57 pm »
this is good stuff, this is realy wonderful, I'm looking forward to some amazing things being done around this...

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Controlling external hardware through Lua
« Reply #6 on: July 14, 2011, 05:35:43 pm »
Great job Jim ;) I'd love a video :)

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: Controlling external hardware through Lua
« Reply #7 on: July 14, 2011, 05:36:51 pm »
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 currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Controlling external hardware through Lua
« Reply #8 on: July 15, 2011, 04:00:08 am »
I'll try to make a video as soon as possible :)

Quote
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.

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: Controlling external hardware through Lua
« Reply #9 on: July 15, 2011, 04:11:28 am »
Well, that's awesome Jim :D

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: Controlling external hardware through Lua
« Reply #10 on: July 15, 2011, 05:12:03 am »
Nice idea jim :)
Ndless.me with the finest TI-Nspire programs

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Controlling external hardware through Lua
« Reply #11 on: July 15, 2011, 06:06:43 am »
Thanks :)

I added a video to the top post. Its not the most clear one though, but you should get the idea :)

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: Controlling external hardware through Lua
« Reply #12 on: July 15, 2011, 06:10:13 am »
Hook a better LCD up to the older Nspires. :D
Omnimaga Admin

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Controlling external hardware through Lua
« Reply #13 on: July 15, 2011, 06:13:11 am »
I might try to control a AV display, as other people have done that already with an arduino.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: Controlling external hardware through Lua
« Reply #14 on: July 15, 2011, 08:52:30 am »
nice. I hope you figure out the input soon. Good luck
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y