Arduino Basic Blender to Arduino Communication

You want to open this screen layout tab because here youre in 3D, you cannot talk to scripting, you want to script so in the script layout tab, you will have all of this. You can have your Properties or something you open here. The most important part is going to be here text and here the console. Now you also want to go to Arduino to make sure youre setting something here. So in Arduino you can have this basic setup. Serial begin, nine thousand six hundred with a string that youre ready to receive and when Siri is going to be more than zero uh some string. You can start to read and if you match the string to the command from the dialogue, you can answer anything and I just put a delay for Arduino not to be over running now. What do we want to do? We want to import by serial because python here, if I import serial, is going to work because I have it. But how do you have it? You take it from PI serial you download, Pi serial Target. Then here you make sure you plug it into here, which here is your blender uh, your blender download here. This is the one Im using you put in this Fender 3.4: the version of blender python, lib and here cereal cereal. So once you plugged it here, you have the restart blender, but I did I did it already so its okay from here I have serial imported.

So I can start to set the variable to Syria uh that Syria. I wanted the class Syrian instance to to work for me and uh. Here you need to check what Arduino Port is on, so is on com7, the other one is not just so my Arduino thats working its on com7, I already uploaded this. You can see. I uploaded this code. Arduino is ready to receive something. So I come here, I put com7 and I also give him the rate and I trade it, and this works so now I can go straight up and look comment here when its going to be received. Hes going to check for these comments, so if I type some comments, there is other than this, its just gon na go into nowhere. But I want to try to print him this comment and to see what hes going to give me Im going to say, Sir, that right and then were in Python, so we have to buffer our string. We cannot give him a a normal string high in Nano, and then you really want to give him a end line because its going to enter instantly here using read string until end line instead of simple, read string, because its going to give us an instant response. Hi Nano it works, they give me some number of bytes. So how do I know the answer of Arduino, sir, that read line? This is what hes going to give me and Im just gon na print out this printer relay and now hes saying yes master.

What can I do for you, this so Im connecting my blender Im from inside blender? I am already talking to Arduino. I have to be careful not to open this uh serial monitor, because serial monitor is going to use this serial from here from inside an arena which means blender will not be able to talk to him anymore. So when blender is talking to him, this serial military is gon na, maybe fail or take over, and then at least I mean theres only one of the two that can work. So here we are. If we want, we can also write everything here: input, Syria and but we first you have to be careful because when Syria is open its the same problem, Syria now we have to serve. That close. Is it closed I think its closed? And then, then we can talk it from everywhere. Again we have to re rewrite this. This is going to reopen the the communication. So here I can import Syria and do the same thing. Basically, sir equals cereal 9600 and then Im going to say, Sir right and Im Im going to ensure that Im closing at the same time, every time I run the script, I will close it to be sure that Im not leaving an open connection for nothing right. Im going to do this um, so this buffer string, type, Nano and end line, of course, and then print – and I should have something going on here.

If I run this Im, pretty sure Im not gon na have no errors lets run it. I have an error: module object is not available for some reason. Ah, this is my problem: Sierra thats, Syria. This is what Im missing, of course, accessory design, because now its open somewhere else so Im gon na close, this Im gon na, have to restore blender. Now, Im copy picking this, I will copy paste this restart going there. So this is a good thing to see that when something is a problem like this, access is denied permission. Error access to the net is because Im already using some Port. So this connection didnt close well because I just import it in a variable. I cannot. I cannot close this variable, sir, is undefined because this failed last time so, sir, I cannot close it even so, I will just have to close blender its going to close the connection for me and restart blender lets see restarting it which frame go to scripting paste. This here import serial zero. This was my mistake. I forgot to call the in the class I just called the the module module cannot be called, and now this should work. No access is denied. Something is working over there because monitor is open. I can start again and now it works, so you see its kind of tricky, sometimes but um, so it works, but it didnt show me anything because I need to toggle system console here and now in the system console it came.

So I have a special plugin that uh, on top of the system, cancel out that writes this console into this console, so Im gon na re enable it python print print to python, console I printed Now it worked perfectly now. I can do this and when that – and here I have my command, so this is how we talk to Arduino.

Share.
Exit mobile version