Using COM ports

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
IndieKid
Citizen
Posts: 80
Joined: Sat Dec 22, 2012 7:05 pm
Contact:

Using COM ports

Post by IndieKid » Thu Feb 09, 2017 12:23 am

Hey everyone. Haven't written anything for a while. I got some kind of weird question.

I started programming microcontrollers. Currently working with ARM Cortex M3 (STM32L152RC). I learned to connect microcontroller to computer using COM port (DE-9) and to transfer data to and from microcontoroller using UART and RS-232.

I wonder if anyone can advise me if there is a way to do some stuff with COM ports inside Love2D. Imagine Love2D game which can be controlled with selfmade old school joystick. It would be awesome.

Thanks for any help and sorry for my English.

--- UPDATE ---

So this is what I've got: https://youtu.be/W2v4NcP3IJE
Last edited by IndieKid on Tue Mar 28, 2017 12:41 pm, edited 2 times in total.

User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Using COM ports

Post by raidho36 » Thu Feb 09, 2017 2:41 am

Just make it a USB joystick. Or write an OS driver that recognizes it as joystick. COM ports nowdays are only kept around for legacy hardware. Modern units use Ethernet and USB.

Having that said, I think I saw somewhere a COM library for Lua.

User avatar
Positive07
Party member
Posts: 1006
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Using COM ports

Post by Positive07 » Thu Feb 09, 2017 7:23 am

I imagine raidho's answer is useless, since you are trying to do this as a hobby and because of fun and the sake of learning, I want to point you out in the direction of connecting a microcontroller through COM ports, being RS-232 or a USB simulating such port, regardless of there being a better option (USB, Ethernet).

My answer is to compile a library. The library I have used is called librs232, and I have experience compiling it under Windows, if you need more information please tell me, I can help you compile this library.

Can you tell us what OS you are using? Linux and MacOS X have file access to COM ports so it's much easier over there, there is a person that has done something simpler for this OSes instead of compiling a library.

librs232 is crossplatform so I still recommend it.
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(Github.com/Positive07)

User avatar
IndieKid
Citizen
Posts: 80
Joined: Sat Dec 22, 2012 7:05 pm
Contact:

Re: Using COM ports

Post by IndieKid » Thu Feb 09, 2017 7:51 am

raidho36 wrote:Just make it a USB joystick. Or write an OS driver that recognizes it as joystick. COM ports nowdays are only kept around for legacy hardware. Modern units use Ethernet and USB.

Having that said, I think I saw somewhere a COM library for Lua.
My fault, forgot to say that I use USB to DE-9 cable, so this could be connected to any computer. Thanks for quick answer.
Positive07 wrote:I imagine raidho's answer is useless, since you are trying to do this as a hobby and because of fun and the sake of learning, I want to point you out in the direction of connecting a microcontroller through COM ports, being RS-232 or a USB simulating such port, regardless of there being a better option (USB, Ethernet).

My answer is to compile a library. The library I have used is called librs232, and I have experience compiling it under Windows, if you need more information please tell me, I can help you compile this library.
Thanks a lot for your help. I'll take a look at this library today.
Positive07 wrote:Can you tell us what OS you are using? Linux and MacOS X have file access to COM ports so it's much easier over there, there is a person that has done something simpler for this OSes instead of compiling a library.

librs232 is crossplatform so I still recommend it.
I have Keil IDE for microcontrollers, so I use Windows for that (using terminals for COM ports). But I have a triple-boot PC with Windows, macOS and Linux, and I'm definetly looking forward on doing a game with COM support for every OS.

User avatar
Positive07
Party member
Posts: 1006
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Using COM ports

Post by Positive07 » Thu Feb 09, 2017 8:03 am

IndieKid wrote:I'm definetly looking forward on doing a game with COM support for every OS.
There probably doesn't exist much people that use a custom device for games, have the same development board as you and will be able to install the code you made for such device in theirs, this segment is probably infimal or non existant... So if you know this and are fine with it then... Sure go for it!
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(Github.com/Positive07)

User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Using COM ports

Post by raidho36 » Thu Feb 09, 2017 8:47 am

No I meant make it have USB interface instead of rs232 interface. As a bonus, it'll work on any PC and with any app. I assume it's over Arduino, it should have USB interface onboard already, and even if not there should be plenty of USB shields.

I have a DIY device ID my own hooked up to my PC, and I made it communicate with PC over USB. It's not a HID device so I have to use libusb on PC side for communication, but it beats messing with COM ports.

User avatar
Positive07
Party member
Posts: 1006
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Using COM ports

Post by Positive07 » Thu Feb 09, 2017 10:41 pm

He means a USB interface, that internally simulates being a COM port. It's not actually RS-232 but they call it that because that was the original protocol for COM ports.

I wouldn't recommend using libusb for such a simple task... yes I know it's better, more customizable, and you can make it into HID, but for simple serial communication COM ports should do, and are an easy way to do the communication, using a USB cable without any bigger complication.
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(Github.com/Positive07)

User avatar
IndieKid
Citizen
Posts: 80
Joined: Sat Dec 22, 2012 7:05 pm
Contact:

Re: Using COM ports

Post by IndieKid » Fri Feb 10, 2017 9:35 pm

raidho36 wrote:
Thu Feb 09, 2017 8:47 am
No I meant make it have USB interface instead of rs232 interface. As a bonus, it'll work on any PC and with any app. I assume it's over Arduino, it should have USB interface onboard already, and even if not there should be plenty of USB shields.
I'm trying to do this with STM32. Started with Arduino, by the way.
Positive07 wrote:
Thu Feb 09, 2017 10:41 pm
He means a USB interface, that internally simulates being a COM port. It's not actually RS-232 but they call it that because that was the original protocol for COM ports.
I am pretty sure that RS-232 is being used in here, because the program loaded to microcontroller works with RS-232. That cable requires driver that simulates a COM port, but on the other end of cable there is a DE-9 that uses RS-232. In other words you just replace one USB port with DE-9 which is a pure COM port.

I am using USB port only because I don't have any COM ports. So this should work on any PC that have COM port.

User avatar
Positive07
Party member
Posts: 1006
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Using COM ports

Post by Positive07 » Sat Feb 11, 2017 7:18 am

Yes, the cable is the standard part, Arduino has an other integrated circuit that does a similar conversion from UART to USB, that kinda thing is pretty common in nowadays microcontroller boards. And their drivers are also easy to find, I have used PIC 18F2550 and 18F4550 simulating COM ports directly from their USB interface couse their memory and Flash limitation don't allow for other complex USB stacks, I also have 3V3 UART to USB cable that I commonly use to interact with the BeagleBone Black serial interface for some complex debugging... All this stuff uses drivers that are commonly available and simple COM interfaces that anyone can access so it's pretty easy to communicate with them, no need to know custom protocols or configurations.

I'll respond to your PM shortly, I'm pretty sure I have 32bit dll version of the library somewhere on my Dropbox, and should work fine with LÖVE for 32 bits for Windows.
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(Github.com/Positive07)

User avatar
BruceTheGoose
Citizen
Posts: 76
Joined: Sat Sep 20, 2014 2:54 pm

Re: Using COM ports

Post by BruceTheGoose » Tue Feb 14, 2017 1:28 am

"I don't know."

Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests