Introduction: Make an Intel Edison Talk to Game Maker: Studio
In this instructable I will show you how to make a program in Game Maker that will notify an Intel Edison when the space button was pressed and then the Edison will tell Game Maker that it received it. This isn't very useful at the moment, but later you could add things like temperature sensors to the Edison and make a weather program on Game Maker that receives the temperature data from the Edison and displays it as a visual.
Things you need:
Game Maker - This is a free program that includes other paid versions. I am using GM:Studio professional
Intel edison w/ expansion board - This is what I used but you might also get by with the Breakout Board
Two usb-to-micro-usb cables
A 7-15 V DC power supply (This is showed in the steps of the link in the next step)
I'm also using Windows 10
I also suggest using two computers, one for all of the Game Maker stuff and the other for all of the Intel Edison stuff. This is because when I used one computer I had problems. Also, if you do this, make sure that if you are using a pc that you use another pc.
Step 1: Set Up the Intel Edison
Intel has a great and easy tutorial for setting up the Edison located here: Setup Edison
(This is where the power supply is shown from the previous step)
Just go through the steps but skip the part that talks about how to set up the other breakout board (unless you use that). Install all of the drivers and software and then continue on with the instructable.
Step 2: Set Up the Arduino IDE
Now we need to actually add the Intel Edison board to the Arduino IDE, so we can program the Edison from there.
1: So go to the Arduino IDE and select the "Tools" dropdown menu
2: Now hover over "Board" and select "Boards Manager..." at the top
3: In the search box, type "intel edison". Only one thing should come up (If not, look at the pictures to make sure). I already have it, so for you, instead of it saying "Remove" it should say "Install". Press install and wait for it to install. Also, you should install every driver that it asks you to.
Step 3: Download the Code
Now you need the Arduino code. Download the code and then click on it once it is. Then press OK when it asks to create a folder for it.
Attachments
Step 4: Edit the Code
Now type your network name and it's password where it is showed in the picture (The top circle). Make sure to keep them inside the quotes. You can also edit the message the Edison will send to Game Maker (The bottom circle). Make sure that is also in quotes as well.
Step 5: Upload the Sketch to the Edison
Now we need to put the code onto the Edison.
First: Right-click on the windows button and select device manager (You can also just search for it on your pc)
Second: Select the dropdown menu called "Ports" and take note of the virtual com port of the Edison
Third: Go to the Arduino IDE and select the "Tools" dropdown menu and, under port, select the port of the virtual com port from the second step.
Last: Now upload the sketch (Code) to the Edison by pressing the circular button with the arrow in it at the top of the IDE.
Step 6: Download the Game Maker File
Now for the Game Maker part
Open Game Maker and go on the "New" tab, type a name for your project and press create
Step 7: Make a New Object
Now in Game Maker right click on "Objects" and create a new object.
Step 8: Name It and Make a Create Event
You don't have to, but I named my object obj_control
Press the "Add Event" button and select the Create event
Step 9: Add the Code in Create Event
Now select the "Control" tab at the right and drag the code block to the "Actions" space to the left.
A new window should pop up that you can type in, but if it doesn't, just double click on the new code block.
Then add this code, there are comments in it that explain what everything is:
var type = network_socket_udp;
socket = network_create_socket(type);//no port since the client doesn’t care //Server IP and port, needed to send packets remote_ip = "192.168.10.214"; //Edison's IP remote_port = 8000; //The port the Edison is on//Make a buffer to hold the message to send to the Edison var size = 1024; var type = buffer_fixed; var alignment = 1; //Make a variable to hold the buffer send_buffer = buffer_create(size,type,alignment);
msg_id = "Nothing yet"; /////////////////////////////
receive_ip = "";
Step 10: Make the Step Event
Now press "Add Event" to add another event and select the Step event.
Just like the previous step, drag a code block into the Actions spot and add this code:
if(keyboard_check_pressed(vk_space))//Check if space is pressed
{ buffer_seek(send_buffer, buffer_seek_start,0);//Set the buffer to the beginning buffer_write(send_buffer, buffer_text, "space pressed"); //Write the string "space pressed" to the buffer //Send the buffer to the Edison network_send_udp_raw(socket,remote_ip,remote_port,send_buffer,buffer_tell(send_buffer)); }
Step 11: Make the Game End Event
Now add a Game End event. To do this, press "Add Event" and press "Other" and select the Game End event
Drag in a code block and put the following code:
///Destroy the server
network_destroy(socket);
Step 12: Add the Networking Event
All of the code in this event is executed when Game Maker receives something from the network, so it only executes when the Edison sends it's reply.
Add a new event called "Networking". To do this, press "Add Event", press "Asynchronous" and select the Networking event
Then add this code:
///If data is recieved, get it, and then store it
var buffer = async_load[? "buffer"]; //async_load[? "buffer"] holds the data that the Edison sends receive_ip = async_load[? "ip"]; //Gt the IP of the Edison buffer_seek(buffer, buffer_seek_start,0);//Set the buffer to the startmsg_id = buffer_read(buffer,buffer_text);//Hold the data in a variable
Step 13: Make the Draw Event
This event is used to display the information we get from the Edison.
Add a Draw event by pressing "Add Event", press "Draw", and then select the very top one (Draw).
Draw a code block and add this code:
///Draw the received data
draw_text(x, y, "Reveived data from ip: " + string(receive_ip)); draw_text(x, y + 32, string(msg_id));
Step 14: Make a Room
Right click on "Rooms" and add a new one
Step 15: Add the Object to the Room
Select the objects tab and click inside the box right below it. Select the object we just created (obj_control) and then click anywhere in the room (The grid area) so that you see the little blue circle.
Step 16: The Grand Finale
You should still have the code running on the Edison, if not then go ahead and upload it (Press the circle with the arrow in it on the top of the Arduino IDE). Once that is uploaded, open the serial monitor by either pressing ctrl+shift+m or by pressing the serial monitor button on the top left of the Arduino IDE. It should eventually say that it is trying to connect. If it doesn't say that after around 20 seconds then (1)try unplugging the Edison from all power, plug it in again and upload the code. If it does say that it is trying to connect, wait about 10 seconds until it says that it connected and says it's IP address and stuff. If it says it is trying to connect more than 3 times try method 1 above. Once it is connected, go to Game Maker and press the GREEN arrow at the top. Don't press the orange one because that will give you something you don't want right now. Once the game has started, press space and you should see the IP address of the your Edison and the message it sent. Also, you should see something in the Arduino serial monitor that has the Game maker PC's information and says "space pressed".
NOTE: If this doesn't work, try plugging in the Edison to a different computer (If you are using a PC, plug it into another PC, not a mac, I got weird results) than the one you run the Game maker program on. Also, if you do this, make sure you do the installation for the Edison drivers on that computer.
ENJOY!