Python with Arduino LESSON 5: Finishing our Virtual Reality Example

This Lesson finishes the work that was begun in Python with Arduino LESSON 4. In that lesson we built the circuit and programmed the arduino to measure the distance to a target and the color of the target. The program then output that data to the serial port. In today’s lesson we will use python to read that data stream, and use the data to dynamically update a virtual world we create.

You will need to start with the work in LESSON 4 to get your circuit working, and your arduino programmed up. Once you have done that, you are ready to use Python to program up your virtual world. Remember you will need to have the pyserial and the vPython libraries loaded. We showed how to install the software in Python with Arduino LESSON 2.

In the video we will go through the process step-by-step to create a virtual world. The code we end up with is posted below. You should not copy and paste the code, but just glance at it if you get stuck. In the end, you should develop your own virtual world and just use mine as a guide if you need more help.

 The video explains each line of the code.  Play around and tweak the values and see the effect on your virtual scene. Now your assignment is to take what you have learned here, and continue to expand your virtual world. Add objects to your virtual scene. Perhaps build an object for the breadboard, color sensor and arduino. I will give you several days to do this, and then when I come around for a project grade, I will want to see who has built the most impressive virtual scene. You should go well beyond the simple demonstration I have done here.

3 thoughts on “Python with Arduino LESSON 5: Finishing our Virtual Reality Example”

  1. Very comprehensive and good instructional and I took your suggestion and created my own virtual world using a MPU6050 6DOF accelerometer and modeled an airplane as a frame component. One hiccup I have noticed is that while I would like to display the plane attitudes as an observer, variables like roll, pitch & yaw in the while loop are additive to the position every time the loop executes and I cannot find sufficient explanation for using the “world” coordinate function. Suggestion?

  2. Traceback (most recent call last):
    File “C:\Users\msi\AppData\Local\Programs\Python\Python36\”, line 8, in
    myScene=display(title=’my world’)
    NameError: name ‘display’ is not defined

    thank you paul, however, “display” doesnot work in my python 3.6 ….i dont know how to fix it, and i do have the vpython library downloaded

Comments are closed.