# How to control real time a hand model, with arduino, flex sensors and voltage dividers?

Hello. I want to make a project where using arduino, flex sensors and voltage dividers, and I want to control real time a hand model in blender (which is rigging ready). I’m using version 3.2.1. The program on the arduino is ready and essentially gives in a continuous loop, the serial output with some voltage values from 5 voltage dividers (which values I can convert into coordinates). But I’m very new with blender and I don’t know how to make the scripting in blender. I have found and I can import the serial library as well as bpy. Could someone please help me by giving me some guidance? Thank you.

Welcome to BA

As an Arduino enthusiast myself, I think it’s really cool what you’re doing here. That being said, I think you’re getting ahead of yourself a bit - for a complex task like this, it may help to break it down into smaller, achievable steps.

For example, right now you have the serial output from the voltage dividers, but that information is meaningless as currently encoded. Start by figuring out the math to convert this to coordinates. You don’t need any scripting to do this, you can just open the n panel sidebar, go to item, and see bone positions. Pose your fingers in a few extremes- stretched out, pointing down, in a fist- and write all those location values down. Make the same motions with your wearable control and compare them- how much does the voltage change compared to the bone location? Is it a factor of 10 bigger? A factor of 100 smaller?

1 Like

Thank you for the answer! I have thought about doing what is described, but I don’t know how this is “translated” into script.

That’s what I mean- you can’t translate it into script until you can first describe the mathematical relationship functionally. Even if you knew Python perfectly you still wouldn’t be able to do anything until you had that relationship mapped out. The script will be easy- it’s just a bunch of “bone[“bone”].location[0] =“ statements combined with serial reading, but you can’t finish that statement unless you know the relationship between your current data and your desired data

1 Like

What I’ve been thinking about doing in regards to assessing and changing the position of the fingers is:

1. Initialize the values ​​in a separate const array (i.e. find the rest values), because the changes that the program will perceive (e.g. due to the movement of a finger) will be made in relation to these values ​​(essentially all will be based on control and comparison structures).
2. To define the extremes of the possible positions that each bone can take in each finger, something that requires a lot of work because the position of each bone depends not only on its own position but also on the position of the other bones in the same finger. So it will take time to make a map of these possible locations (in coordinate form) for each finger.
1 Like

Also, there is this….Need an account to read the full document

2 Likes

I think, the easier and less hacky way would be to create pose assets with each finger in it’s extreme position(https://youtu.be/3pd_ftb0z5g don’t forget to enable pose library addon), add all their actions to NLA editor(https://youtu.be/Hz1TwvSNsrA) on different layers and then change the corresponding “Animated Influence” parameter using python(you can right click on this property and copy full data path), this would look something like this:
`bpy.data.objects["Armature"].animation_data.nla_tracks["NlaTrack.002"].strips["Finger.001"].influence = finger_data[0]`
The only limitation I see, is that the animation should be playing inside blender for changes to be visible(just press “shift+space” or just “space”, depending on your configuration)

1 Like

Thank you for the answer! I’ve seen that paper but it doesn’t mention anything specific about script in Blender.

I have no clue about arduino but I assume that you read serial data like this:
https://create.arduino.cc/projecthub/ansh2919/serial-communication-between-python-and-arduino-e7cce0

If you throw this line into a modal operator it would be feasible to change any value needed.
`data = arduino.readline()`

1 Like