Connecting to a usb port?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Connecting to a usb port?

Post by Plu »

Right, so for a gamejam next week my team is planning to use some external hardware hooked into a löve application to display the scoreboard.

This means I need to communicate with an Arduino server over a USB connection.

I figured that this would require using luaSocket, but can anyone give me a few pointers? I don't have the Arduino at home so I can't actually play around with it but I'd rather not go into the jam entirely unprepared. How can I use luaSocket to connect to the Arduino and read its data? Just setting up the socket and reading bytes from it should pretty much be enough, I can probably handle the rest myself when the jam starts (I'm not sure what they'll be sending anyway).

Is it as easy as opening a UDP connection to a specific port? And how would I find the right port? Or is there more to it?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Connecting to a usb port?

Post by raidho36 »

LuaSocket is for networking, not for serial data transfer.

You'd have to write device driver from scratch. See AVR (or whatever chip you got there) programming guides.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Connecting to a usb port?

Post by Ranguna259 »

Can löve actually do that, aren't we restricted to löve's directories ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Connecting to a usb port?

Post by Plu »

A device driver for pulling raw data from a USB port? Seriously? :(

That'd make things a bit more complicated.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Connecting to a usb port?

Post by raidho36 »

Well what did you expected? Your PC to have magically standardized USB serial data transfer driver 100% compatible to your setup out of zillions available, and have your firmware magically match requested parameters?

Yes, you'd have to write the driver for the PC. And, the firmware for the device. Easiest way of course is to use serial port (COM), USB is vastly more complicated but still quite doable, it's just USB baudrate is a lot higher, while only 2 data channel are actually available. USB 3.0 uses more pins, which adds two simplex extra channels for both input and output, with effectively 4 channels in each direction. It's kinda complicated, unless you REALLY need the USB, you better off with COM.

So what do you do, basically: create a firmware that receives some input data and does something. Make sure to work out all the bugs, since bugs in hardware are much less pleasant thing than bugs in some PC app. You'd have to learn C in great depth as a bare minimum, preferably assembly language, in as much depth. Otherwise your chip will run like shit and will yield such a behavior that "undefined" doesn't even start to describe it.

Then create a software PC backend that would send some data via COM/USB/whatever, and expect the device to do something. You can even use LÖVE for the backend, if you can hook up USB/COM handling library.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Connecting to a usb port?

Post by Plu »

Well what did you expected?
Well, I expected the lowest level implementation to be available... you know, connect to the port and read raw binary data from it. But if even that isn't there, I guess we're going for an alternative solution.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Connecting to a usb port?

Post by raidho36 »

Reading and sending data to the USB/COM port is one thing. Reading and sending data from within the chip is the whole different story.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Connecting to a usb port?

Post by Plu »

I'm not concerned about reading and sending data from within the chip. That's on the guy building the Arduino, and that part is already working. I just need to be able to read and send raw binary data over the USB/COM port. I'll handle the formatting myself, it's all really straight-forward string-based commands.

Maybe I worded it poorly... the Arduino chip has a USB plug, and it's already configured to read and send data over its serial port. I just need to be able to read/write to the USB port on the desktop's side so that my löve script can pick up the messages that the Arduino is sending out.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Connecting to a usb port?

Post by raidho36 »

Then you need some .dll/.so to connect to the USB port bypassing the OS, I dunno however you say it right but you get the idea.

Also, arduino is for 143m n00bz.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Connecting to a usb port?

Post by Boolsheet »

If the device automatically sets itself up as a client, maybe you could use libusb and Lua bindings for it.
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: No registered users and 211 guests