Jump to content


Photo

Arduino + Game Maker


  • Please log in to reply
47 replies to this topic

#1 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 318 posts
  • Version:Unknown

Posted 02 February 2012 - 01:49 AM

The Arduino DLL is here!

 

Finally an Arduino specific DLL for Game Maker that works with both Studio and earlier GM versions on windows. The DLL is a modified port of the C++ Serial Class from the Arduino playground. The functionality is designed to be simple and easy to use, it also supports multiple Arduinos.

 

Download: Arduino DLL

C++ source and Codeblocks project included.

 

Function rundown:

arduino_init() - Initializes the dll, call this first before doing anything else.

 

arduino_create("COM3") - Creates an arduino serial connection and returns the unique id of this Arduino to be used in later calls.

 

arduino_connected(id) - Returns whether or not the Arduino is connected.

 

arduino_read(id, length) - Returns a string of data from the arduino or a negative number on error.

 

arduino_write(id, data, length) - Writes a string to the Arduino, returns whether successful or a negative on error.

 

arduino_delete(id) - Deletes an Arduino, freeing it from memory.

 

arduino_destroy() - Deletes all arduinos and frees the DLL from memory.

 

Enjoy,

RobotiX

 

 

 

********************************************************************************************************************************************************************************

********************************OLD POST - The following is very outdated and should not be used over the above.*****************************************

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

****************************************************************************************************************************

Edit: *Link updated 7/9/2015


Edited by Buff-Robotix, 10 July 2015 - 05:57 AM.

  • 4

#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
  • 17247 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
  • 318 posts
  • Version:Unknown

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
  • 8 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
  • 318 posts
  • Version:Unknown

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
  • 8 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
  • 318 posts
  • Version:Unknown

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
  • 8 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
  • 17247 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
  • 318 posts
  • Version:Unknown

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
  • 318 posts
  • Version:Unknown

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
  • 58 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
  • 3 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
  • 318 posts
  • Version:Unknown

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

#31 Crollo

Crollo

    GMC Troll

  • GMC Member
  • 1019 posts

Posted 22 July 2014 - 09:52 AM

The RS232 extension works fine with an Arduino Uno board.

Thank you for pointing me to this awesome extension, anybody in doubt or having problems I can assure you it's working fine:
hqdefault.jpg?1405993571353

 

To anybody having problems, perhaps you have my case of bad luck which was that the COM port my Arduino was reading was was ridiculously high (22) and it refused to work. After a clean install of windows the next time I installed it, it read as COM3 and then the project worked fine. So maybe reinstall your drivers for the Arduino and\or clean out your COM ports.


Edited by Crollo, 22 July 2014 - 10:00 AM.

  • 0
Posted Image

#32 AlexDAK43

AlexDAK43

    GMC Member

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

Posted 22 April 2015 - 06:32 PM

There is no mplay function in GM Studio anymore. Do you know any way to communicate with LPT or COM in GM Studio? Now I save data to file in GMS and read this file in Visual Basic programm and send data to COM, but it's too complicated and not very fast.


  • 0

#33 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 318 posts
  • Version:Unknown

Posted 22 April 2015 - 10:49 PM

There is no mplay function in GM Studio anymore. Do you know any way to communicate with LPT or COM in GM Studio? Now I save data to file in GMS and read this file in Visual Basic programm and send data to COM, but it's too complicated and not very fast.

I'm afraid the only way to do it now is for someone to write an Arduino specific DLL for GM:S. Using the Arduino C++ example it shouldn't be too difficult to make. They also have examples in C and C# as well as many other languages that could possibly create DLLs, I've considered doing this but I don't have a need for it or much free time. This would give you a direct line of communication to the Arduino from GM:S.

 

RobotiX


  • 0

#34 meliaz99

meliaz99

    GMC Member

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

Posted 01 July 2015 - 09:06 AM

Sorry for bumping this old topic cause I need some help.

My problem is the same as Zpace.

 

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!

 

I'm using Arduino Mega. The RX led arduino board flashes, but the led light won't change state from OFF, ON, or BLINK.

Did anybody find a fix? Or at least tell me what's wrong, solution, etc.

Any help will be so much appreciated!


  • 0
76561198094963167.png

#35 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 01 July 2015 - 05:31 PM

I made a dll from post 33....
https://drive.google...Qkx6aE44aUtpa0k

I dont have an arduino, I have no idea if it works and I have no idea of what the serial interface defined by arduino is... like what commands can be sent or what can be read (and when) and what format to use... But at least this implementation is from a known source...

The function use a game maker buffer so in theory you can format you calls to anything you want even though I did not include any Arduino specific commands in there... we could add those in...

Tell me if you manage to get something working and what is needed to supplement the dll with more specify arduino functions.

Edited by icuurd12b42, 01 July 2015 - 05:36 PM.

  • 1

#36 meliaz99

meliaz99

    GMC Member

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

Posted 05 July 2015 - 07:54 AM

@icuurd12b42

 

Sorry for late reply, I just want you to know that I surprisingly can connect GM:S to Arduino with your dll! (I noticed it when the arduino start blinking when I started my game).. This is awesome! Thank you so much!... But this dll fail at writing data to Arduino (or is it?) cause everytime I use Arduino_WriteData() the RX led is not blinking.. . .

 

I see your wrote some "example" call in the Arduino_WriteData script, but since I want to try sending very simple data first, so I just comment all your example calls. And I tried this. I'm doing it right, aren't I?

 

    abuff=buffer_create(256,buffer_grow,1);
    buffer_seek(abuff, buffer_seek_start, 0);
    buffer_write(abuff, buffer_u8, 100);
    
    if (Arduino_WriteData(global.Arduino,abuff)==false)
        {
        show_message("Error sending buffer: "+string(Arduino_GetLastError()));
        } 
    else
        {
        show_message("Sent! "+string(Arduino_GetLastError()));
        }
 
It turns out the dll think it's sent while the Arduino never received the data.

 

In case you want to know my experience with Arduino, I'm quite a new user. I previously managed to create a successfull line follower robot, and other kind of stuff, but I never work with serial communication. I have no basic in communication. :/

 

Sorry for my bad English..


  • 0
76561198094963167.png

#37 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 05 July 2015 - 03:30 PM

That's the thing. I dont know if it fails or if the data you send it is incorrect because I dont know if the stream is expecting commands in text form like

writing a string
"SET PIN 0 HI"
or a text field with string 0 and ones
writing string
"01001001"

or data in binary form...
writing a byte at the right offset
write byte 2 for {00000010}

I found this...
http://webtutsdepot....-plus-tutorial/

and this is not taking into account any typos I may have made in the GML side of things as well...

also there is no mention if one needs to clear the the stream and if so when? because the same stream is used for input and output by 2 devices... I assume the following happens though I may be wrong

You write commands
"COMMAND DO SOMETHING"
the stream is
COMMAND DO SOMETHING
your file pointer should be
COMMAND DO SOMETHING<HERE>

and the arduinot write results like
"ACKNOWLEDGE"

the stream is
COMMAND DO SOMETHINGACKNOWLEDGE

the arduino file pointer would be
COMMAND DO SOMETHINGACKNOWLEDGE<HERE>

while your file pointer on your end should be
COMMAND DO SOMETHING<HERE>ACKNOWLEDGE

so you would maybe need to do a read string to grab the stuff or do a seak to the end ... but I dont know. at this level you have to know everything about how that port communicates...
the source is included you should be able to compile the project in either code::block (recommended to "final" compile without dependencies) or MS Visual Studio (Which allows debugging the dll)...

Edited by icuurd12b42, 05 July 2015 - 03:54 PM.

  • 0

#38 Nexusrex

Nexusrex

    WRYYYY!

  • GMC Member
  • 429 posts
  • Version:GM8

Posted 05 July 2015 - 04:12 PM

This is awesome..Also i was starting learning arduino..But, how useful could this be?


  • 0

e5LGZAz.png

My W.I.P Sidescrolling Shooter


#39 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 318 posts
  • Version:Unknown

Posted 07 July 2015 - 03:12 AM

I have been extraordinarily busy lately but I made a DLL a few months ago, likely similar to icuurd's, based on Arduino's C++ serial class. It supports multiple Arduinos and is very simple to use. I didn't get to test it though because all of my Arduinos stopped working for no conspicuous reason. In theory it works. But I didn't have time to post it till now. The C++ code is very simple, it's really just a wrapper for the Arduino serial class. In any case, here it is.

 

Arduino DLL.


  • 1

#40 meliaz99

meliaz99

    GMC Member

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

Posted 08 July 2015 - 12:18 PM

@Nexusrex

 

I'll do this just for fun. Probably not so useful with GM. But imagine the possibilities! Using servos for gaming, light sensors, distance sensors etc. Developing a game will be funnier than before!

 

@Buff-Robotix

 

Wow. And practically your code works like a charm. Thank you so much sir. This is something special. And you know what? I made a game with your DLL! I use 8 light sensors from my old Robot to work with this game. Have a watch. :)

 

 

...

 

Oh yeah, when I tried opening your example using GM:Studio, there is some error at defining external function which I don't understand. I guess I need to learn to create a DLL. 


  • 1
76561198094963167.png

#41 Nexusrex

Nexusrex

    WRYYYY!

  • GMC Member
  • 429 posts
  • Version:GM8

Posted 08 July 2015 - 12:48 PM

What an awesome idea..@meliaz...Nice video..Well..Now i could create my joystick using arduino..But, does it need a special arduino..Or it could work with Uno R3?


  • 0

e5LGZAz.png

My W.I.P Sidescrolling Shooter


#42 meliaz99

meliaz99

    GMC Member

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

Posted 08 July 2015 - 01:07 PM

It should work with Uno if you have the shield and enough pins.
  • 0
76561198094963167.png

#43 Nexusrex

Nexusrex

    WRYYYY!

  • GMC Member
  • 429 posts
  • Version:GM8

Posted 08 July 2015 - 01:13 PM

Which shield??

In my normal arduino projects..I use a solderless breadboard..If you mean the shield for motors..I could use one or connect it to the breadboard..


  • 0

e5LGZAz.png

My W.I.P Sidescrolling Shooter


#44 meliaz99

meliaz99

    GMC Member

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

Posted 08 July 2015 - 01:26 PM

Wait, I guess I'm wrong. I kinda new with Arduino so, yeah. In my Arduino mega, I use an expansion shield to get more pins. I'm not sure you need it or not.

Try it, and tell us if you made it! xD
  • 0
76561198094963167.png

#45 Nexusrex

Nexusrex

    WRYYYY!

  • GMC Member
  • 429 posts
  • Version:GM8

Posted 08 July 2015 - 01:30 PM

I'm also new..Didn't make lots of projects (Only one)

Maybe i could try using my buttons to make movement..As a test! xD


  • 0

e5LGZAz.png

My W.I.P Sidescrolling Shooter


#46 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 318 posts
  • Version:Unknown

Posted 08 July 2015 - 03:10 PM

@Nexusrex

 

do this just for fun. Probably not so useful with GM. But imagine the possibilities! Using servos for gaming, light sensors, distance sensors etc. Developing a game will be funnier than before!

 

@Buff-Robotix

 

Wow. And practically your code works like a charm. Thank you so much sir. This is something special. And you know what? I made a game with your DLL! I use 8 light sensors from my old Robot to work with this game. Have a watch. :)

 

 

...

 

Oh yeah, when I tried opening your example using GM:Studio, there is some error at defining external function which I don't understand. I guess I need to learn to create a DLL. 

Wow, this is great! I'm glad it works, that's a really neat game. I'll take a look at Studio compatibility when I get home from work.

 

RobotiX


  • 0

#47 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 08 July 2015 - 05:35 PM

Care to tell use how writing and reading arduino information work now that you have figured it out? I'm an old hardware fan so I'm curious.
  • 0

#48 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 318 posts
  • Version:Unknown

Posted 10 July 2015 - 05:41 AM

Figured out what was wrong with Studio. I forgot they removed the ability to make arguments optional in scripts so you have to put something. I fixed the scripts and updated the link, should work with both versions now. Make sure you have the dll as an included file in Studio.

 

Arduino DLL


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users