Jump to content


Photo

Arduino + Game Maker


  • Please log in to reply
30 replies to this topic

#1 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 314 posts

Posted 02 February 2012 - 01:49 AM

This may be in the wrong forum, and might get moved...

At long last I am finally able to connect Game Maker and Arduino seamlessly through the RS232 DLL by andbna. Today I share this with you.
I have made an example that includes how to write bytes to the Arduino and how to read bytes from it. You must be fairly fluent in the Arduino language in order to use this technique effectively.
Included in the following download is the gmk (GM8) example, the RS232 DLL and gml scripts for it, and the Arduino pde file.

Download

The technique makes use of the RS232_WriteByte() function to write to the Arduino and Arduino's Serial.read() function to read from Game Maker.
Similarly it uses Arduino's Serial.print() function to write to Game Maker and RS232_ReadByte() to read from the Arduino.
You can also use RS232_ReadString() to read strings from the Arduino and RS232_WriteString() to write strings to the Arduino.

Using this example
  • First open up the GMBlink.pde in your Arduino programing program. Read and understand it.
  • Download the sketch to your Arduino.
  • Then open up the Arduino_Blink.gmk in Game Maker. Read and understand it.
  • Now find the port your Arduino is plugged into, this can be found in the device manager.
  • Change the com variable to your COM port.
  • Then run the game and you should be able to control your Arduino's LED with the spacebar.
With this new expansion of Game Maker we can effectively connect our computers to the real world with sensors and motors and such.
Game Maker is so versatile and easy we can easily prototype Arduino programs very quickly.

For more information about the Arduino visit their website.
For more information abut the RS232 DLL and for the extension go here. Credit goes to andbna for this awesome DLL

If you have any questions just comment.
I have only tested this on my Arduino Duemilanove and I would like to see if it works on others too, so please test it if you have an Arduino.

Enjoy,
RobotiX

Edit: *Link updated 2/22/13

Edited by Buff-Robotix, 22 February 2013 - 07:52 PM.

  • 2

#2 getty

getty

    GMC Member

  • New Member
  • 16 posts
  • Version:Unknown

Posted 02 February 2012 - 02:32 AM

That's amazing! I've been planning to use arduino for a while now. I will be using this, definitely.
  • 0

#3 c_stallworth

c_stallworth

    GMC Member

  • New Member
  • 5 posts
  • Version:GM8

Posted 08 February 2012 - 06:56 AM

This seems to be what I need. However, I click on Download and get Chinese. How can I get your files? Please help.
  • 0

#4 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 16179 posts
  • Version:GM:Studio

Posted 08 February 2012 - 07:37 AM

This seems to be what I need. However, I click on Download and get Chinese. How can I get your files? Please help.

Works fine now
  • 0

#5 c_stallworth

c_stallworth

    GMC Member

  • New Member
  • 5 posts
  • Version:GM8

Posted 08 February 2012 - 08:00 AM

Forgive my mistake, I was using the wrong character set. I have everything installed and understand the code, but can't get the communication going.
  • 0

#6 c_stallworth

c_stallworth

    GMC Member

  • New Member
  • 5 posts
  • Version:GM8

Posted 08 February 2012 - 08:04 AM

My Arduino is connected to com port 37. I change the value of the com variable in the code for the create event, but to no avail.
  • 0

#7 c_stallworth

c_stallworth

    GMC Member

  • New Member
  • 5 posts
  • Version:GM8

Posted 08 February 2012 - 08:33 AM

My Arduino is connected to com port 37. I change the value of the com variable in the code for the create event, but to no avail.


Changed the port number of the Arduino to 4 and I am now able to communicate from GM to the Arduino. However, I am not successful when I try to open the serial monitor in my Arduino programming environment to try to communicate from the Arduino to GM. I get the error message 'Serial port 'COM4' already in use. Try quitting any programs you may be using.'. Please assist. Thank you.
  • 0

#8 c_stallworth

c_stallworth

    GMC Member

  • New Member
  • 5 posts
  • Version:GM8

Posted 08 February 2012 - 08:46 AM


My Arduino is connected to com port 37. I change the value of the com variable in the code for the create event, but to no avail.


Changed the port number of the Arduino to 4 and I am now able to communicate from GM to the Arduino. However, I am not successful when I try to open the serial monitor in my Arduino programming environment to try to communicate from the Arduino to GM. I get the error message 'Serial port 'COM4' already in use. Try quitting any programs you may be using.'. Please assist. Thank you.


Persistence has won out. I now understand my errors and realize that the application was working properly. Input from the serial monitor was not needed. I can now go to bed with visions of coolness dancing in my head. Thank you for sharing this.
  • 0

#9 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 314 posts

Posted 10 February 2012 - 09:12 PM

I'm sorry I wasn't here to help you and I'm glad everything ironed itself out.
It is true that you cannot open up the Arduino Serial Command window while you are connected to the Arduino with GM or anything else for that matter, only one program can be connected to the Arduino at a time. Any communication from the Arduino must be downloaded before hand and triggered by GM.

I'm glad everyone is getting it to work and having a good time. I think some really cool ideas will come from this.

RobotiX
  • 0

#10 Techno-Q

Techno-Q

    GMC Member

  • GMC Member
  • 7 posts
  • Version:GM8.1

Posted 04 November 2012 - 10:59 PM

I'm Sorry, this post is an error!

Edited by Techno-Q, 14 November 2012 - 10:00 PM.

  • 0

#11 Techno-Q

Techno-Q

    GMC Member

  • GMC Member
  • 7 posts
  • Version:GM8.1

Posted 14 November 2012 - 12:19 PM

I'm Sorry, this post is an error!

Edited by Techno-Q, 14 November 2012 - 10:01 PM.

  • 0

#12 Techno-Q

Techno-Q

    GMC Member

  • GMC Member
  • 7 posts
  • Version:GM8.1

Posted 14 November 2012 - 12:28 PM

I'm Sorry, this post is an error!

Edited by Techno-Q, 14 November 2012 - 10:02 PM.

  • 0

#13 Tarik

Tarik

    GMC Member

  • GMC Member
  • 2731 posts
  • Version:GM:Studio

Posted 15 November 2012 - 04:34 AM

Sweet! Might be time to stop checking out Arduino videos and building one myself haha. Could build a dedicated controller for my games :P

Thanks a lot for your efforts. I hope to return sometime soon. Would you keep us up to date on your endeavours?
  • 0

#14 Techno-Q

Techno-Q

    GMC Member

  • GMC Member
  • 7 posts
  • Version:GM8.1

Posted 15 November 2012 - 05:13 AM

OK, I have loaded the arduino with the blink sketch. I have opened the Blink.gmk inGM8.1., and ran the program. The room comes up and responds to the keybord.

However the light on the Arduino is not responding to the commands. My com port is set to 4.
I know the arduino is working because it works with other sketiches.
I donít think that I am connected, Or am I?

Anyone know what I should try next?
  • 0

#15 AmirBayareh

AmirBayareh

    GMC Member

  • New Member
  • 4 posts
  • Version:GM:Studio

Posted 24 February 2013 - 07:06 AM

Hello, I have a problem, I can't get the device to work properly, any time I try to set the modes for the blink the only light that flashes is the one labeled "RX".
The COM ports are fine, already changed the number to the COM the Arduino is connected to.
If someone could please help me, I would apreciate that so much!
:laugh:/>
  • 0

#16 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 314 posts

Posted 24 February 2013 - 07:09 AM

Hey Amir,What kind of Arduino do you have? Does it have an led hooked up to digital pin 13?
  • 0

#17 BluebirdoBluB

BluebirdoBluB

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8.1

Posted 27 February 2013 - 02:36 AM

Hi all,

This interface looks awesome, but does anyone know if it can work with Game Maker Studio? I have the free version through Steam, but it gave some error messages about opening old game maker files. I know some free versions have restrictions on custom DLLs, and I'd like to be sure what I can use this with, before I commit to buying anything if necessary.

Thanks!
  • 0

#18 AmirBayareh

AmirBayareh

    GMC Member

  • New Member
  • 4 posts
  • Version:GM:Studio

Posted 27 February 2013 - 05:33 AM

Hey Amir,What kind of Arduino do you have? Does it have an led hooked up to digital pin 13?

Hello there, I have the Arduino UNO, and I finally got it working, thank you so much for the reply =), the problem was that I didn't set the serial Number in every function, now I got to control a servomotor trough Game Maker, and even build a minigame that showed the enemy health bar as an array of leds.
  • 0

#19 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 314 posts

Posted 27 February 2013 - 06:05 AM

That's great Amir! Some practical implementations. If you are willing to share I'd be interested on how you transferred the data. I used to be able to do strings just fine with Serial.print("Hello world"); and RS232_ReadString(11,1); but I have been running into problems and currently the only reliable form of communication I can achieve is sending bytes which is incredibly limited. I think its about time I get an UNO, my Duemilanove is getting pretty old.

BluebirodBluB: I know that many dlls do not work with studio. I will give it a shot and see what I come up with.

RobotiX

Edited by Buff-Robotix, 27 February 2013 - 07:57 AM.

  • 0

#20 AmirBayareh

AmirBayareh

    GMC Member

  • New Member
  • 4 posts
  • Version:GM:Studio

Posted 28 February 2013 - 04:34 AM

That's great Amir! Some practical implementations. If you are willing to share I'd be interested on how you transferred the data. I used to be able to do strings just fine with Serial.print("Hello world"); and RS232_ReadString(11,1); but I have been running into problems and currently the only reliable form of communication I can achieve is sending bytes which is incredibly limited. I think its about time I get an UNO, my Duemilanove is getting pretty old.

BluebirodBluB: I know that many dlls do not work with studio. I will give it a shot and see what I come up with.

RobotiX


I would be pleased to share what I have done until now ^^, but I won't be available until this weekend, so I'll share the code and some instructions for the arduino maybe on saturday. I also have some problemas too for reading some chars from serial ports, but we may find a solution for this issues =)
  • 0

#21 BluebirdoBluB

BluebirdoBluB

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8.1

Posted 22 March 2013 - 07:09 PM

So quick question, the RS232_ReadByte() has only one argument right? The number of bytes to read from the buffer? So if say, I had one byte on which direction to move a character, and a second byte on whether or not to fire a bullet, it would look like "RS232_ReadByte(2)"? Is there a maximum amount that can be read at once with ReadByte()? A simple explanation of the argument for this function would be much appreciated, thanks.

 

Hope no one minds, but I posted this same question in (http://gmc.yoyogames...hl=rs232&page=3) just in case someone say one before the other. If this is too redundant or clogs up the responses, feel free to remove one.


  • 0

#22 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 16179 posts
  • Version:GM:Studio

Posted 22 March 2013 - 07:54 PM

The buffer limit is mentioned somewhere for the whole data read... That limit alone make the byte array/string size small enough to not be a concern, think of is as file io... those too have a buffer size smaller than what you could allocate...

 

you can pack 8 boolean flags in a single byte

you can read a 0-255 value byte

you can read a short, integer, anythiong in a formated binary file format along with type conversion....

 

There is the Buffer system in Studio

buffer_write(buffer, type, value)

 

I had GMBinfile prior to this in < GM8.1 .

 

To save a string it is likely written like this,

write the size of string to buffer/file as integer

var len; len = string_length(argument1)

write_int(filehandle(argument0),len)

var i; i=0;

repeat(len)

write_byte(argument0,string_char_at(argument1,i))

 

giving this format in the buffer

12Hello There!12How are you?

 

to read, you do the process with buffer_read(buffer, type)

 

but Studio does it for you, all you need to do is match each read type to each write type in the buffer/game data stream...

 

Here I would wish for Studio to also be able to stream instances for me to match every "view" on my game, aka multi-player... I'm trying to figure out a way to convert instances to GUID references so that created things couljd be shared between running instances of my game.


  • 0

#23 BluebirdoBluB

BluebirdoBluB

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8.1

Posted 23 March 2013 - 05:07 AM

I'm a little confused, are you answering me or someone else? I have GM 8.1, not Studio, so I'm not sure what you're saying. Do you know the answer for my post in 8.1?

The buffer limit is mentioned somewhere for the whole data read... That limit alone make the byte array/string size small enough to not be a concern, think of is as file io... those too have a buffer size smaller than what you could allocate...

 

you can pack 8 boolean flags in a single byte

you can read a 0-255 value byte

you can read a short, integer, anythiong in a formated binary file format along with type conversion....

 

There is the Buffer system in Studio

buffer_write(buffer, type, value)

 

I had GMBinfile prior to this in < GM8.1 .

 

To save a string it is likely written like this,

write the size of string to buffer/file as integer

var len; len = string_length(argument1)

write_int(filehandle(argument0),len)

var i; i=0;

repeat(len)

write_byte(argument0,string_char_at(argument1,i))

 

giving this format in the buffer

12Hello There!12How are you?

 

to read, you do the process with buffer_read(buffer, type)

 

but Studio does it for you, all you need to do is match each read type to each write type in the buffer/game data stream...

 

Here I would wish for Studio to also be able to stream instances for me to match every "view" on my game, aka multi-player... I'm trying to figure out a way to convert instances to GUID references so that created things couljd be shared between running instances of my game.


  • 0

#24 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 314 posts

Posted 29 March 2013 - 07:06 AM

So quick question, the RS232_ReadByte() has only one argument right? The number of bytes to read from the buffer? So if say, I had one byte on which direction to move a character, and a second byte on whether or not to fire a bullet, it would look like "RS232_ReadByte(2)"? Is there a maximum amount that can be read at once with ReadByte()? A simple explanation of the argument for this function would be much appreciated, thanks.

 

Hope no one minds, but I posted this same question in (http://gmc.yoyogames...hl=rs232&page=3) just in case someone say one before the other. If this is too redundant or clogs up the responses, feel free to remove one.

 

I believe you are mistaken. The one argument in ReadByte is the id of the port that you created that you would like to read from.


  • 0

#25 BluebirdoBluB

BluebirdoBluB

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8.1

Posted 31 March 2013 - 08:53 PM

So quick question, the RS232_ReadByte() has only one argument right? The number of bytes to read from the buffer? So if say, I had one byte on which direction to move a character, and a second byte on whether or not to fire a bullet, it would look like "RS232_ReadByte(2)"? Is there a maximum amount that can be read at once with ReadByte()? A simple explanation of the argument for this function would be much appreciated, thanks.

 

Hope no one minds, but I posted this same question in (http://gmc.yoyogames...hl=rs232&page=3) just in case someone say one before the other. If this is too redundant or clogs up the responses, feel free to remove one.

 

I believe you are mistaken. The one argument in ReadByte is the id of the port that you created that you would like to read from.

Okay, that helps some.  Does ReadByte() read everything currently in the Serial buffer then? After reading, does it automatically delete from the buffer what it reads, or do I have to do that myself with another function? I'm trying to get my game working with several control inputs, so instead of reading from only one I'm reading from several.

 

Is there a help file or site somewhere that explains all the functions in this rs232 dll, what they do, what their arguments mean, stuff like that? How did you find this out?


  • 0

#26 BluebirdoBluB

BluebirdoBluB

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8.1

Posted 31 March 2013 - 09:09 PM

Also, does the rs232 implementation in GM here have any functions like these (for the Arduino)?

http://arduino.cc/en/Serial/Available

http://arduino.cc/en/Serial/Flush

 

I have an idea about how to serially communicate multiple bytes using the arduino, but the problem is, I don't know how to translate something like this into rs232 Game Maker's implementation. Any help is appreciated.


  • 0

#27 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 314 posts

Posted 01 April 2013 - 05:55 AM

Yes the help file with all the function explanations is included in the zip mentioned in this post on the RS232 DLL topic http://gmc.yoyogames...36461&p=2397339

This will also answer your other questions but I can tell you there are no functions like available and flush. Although you can still use these functions on the Arduino end.

 

RobotiX


  • 0

#28 Zpace

Zpace

    GMC Member

  • GMC Member
  • 55 posts

Posted 11 September 2013 - 09:07 AM

I have an Arduino Uno and I can't get this to work. Every time I tap the spacebar (send a byte) for example, the RX led on the Arduino board flashes, but it's like it doesn't recieve the byte anyway, because the led light wont switch between the states (OFF, ON, BLINK).

 

Is there something special that needs to be added to the code when you use an Arduino UNO?

 

I saw that AmirBayareh had one and managed to solve the problem but I don't understand what he means when he says: "the problem was that I didn't set the serial Number in every function".

What serial number? The baudrate? The com-port? The acutal byte I'm sending?

Also, which functions? In gamemaker? In the arduino sketch?

 

I need some help solving this problem. All answers are appreciated!


  • 0

#29 Alfredogtz92

Alfredogtz92

    GMC Member

  • New Member
  • 1 posts
  • Version:Unknown

Posted 09 April 2014 - 07:40 PM

Sorry for the stupid question, but how can I include the dll extension to the example you created? I previously had the RS232.gex from another topic, but it can't find the location where the dll is, even when I already placed it in the project's directory.
 

The project recognises the script functions but can't recognize the dll functions, so impossible to run your example. I'm looking forward to modify it but first of all I need to make this to work.

 

Any help would be appreciated.


Edited by Alfredogtz92, 09 April 2014 - 07:41 PM.

  • 0

#30 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 314 posts

Posted 09 April 2014 - 10:38 PM

Hello!

It has been quite a while since I've worked on this project and I believe it is in need of an update. When I have the time I would like to try playing around with Arduino and GM:S.

 

Sorry for the stupid question, but how can I include the dll extension to the example you created? I previously had the RS232.gex from another topic, but it can't find the location where the dll is, even when I already placed it in the project's directory.
 

The project recognises the script functions but can't recognize the dll functions, so impossible to run your example. I'm looking forward to modify it but first of all I need to make this to work.

 

Any help would be appreciated.

No such thing as a stupid question!

My example uses the DLL only and not the extension, if you use both the functions will conflict. The best way to get it to work right out of the zip would be to not include the RS232 Extension and let the RS232 Scripts handle communicating with the DLL. Note that the DLL must be called "RS232.dll" and must be in the same folder.

 

Extensions are nice though because the function names are integrated into the IDE so if you would want to use the extension instead, you must delete all the RS232 scripts in GM and include the RS232 Extension. Also be sure to get rid of RS232_Startup() on line 6 of the create event because this function is not necessary for the extension to work.

 

This system may be outdated and might not work correctly anymore so I can't speak for it's volatility, but I am interested in exploring with it in the future.

 

*Edit* Just found my old Duelminove and literally blew dust off of it. But I plugged it in, uploaded the sketch, opened the serial moitor, closed it, and ran the Game Maker program and it worked like a charm. But when running it again, it doesn't work, at all. This is the kind of volatility I mentioned. When I first started this project I had an issue where the Arduino board would only connect to the GM program after the Arduino Serial Monitor was opened up once. This was an issue I tried to resolve using the Mplay functions. It would seem that it seized to work. I'll look into it.

 

RobotiX


Edited by Buff-Robotix, 09 April 2014 - 10:49 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users