End Presentation


TWiki Slide Show
Next
Reading the Color Sensor and the Virtual World

Session 3 of the AFNOG tutorial
on IoT sensors

Uli Raich

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 1 of 17





















TWiki Slide Show
Next
How to create the Virtual World
We have seen the image of

  • the ultra-sonic sensor
  • the color sensor
  • the colored paper
Having a closer look we see that it is composed of simple 3d objects:

  • cylinders
  • boxes
  • a sphere
scene-1.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 2 of 17





















TWiki Slide Show
Next
Videos
Some of the examples in the slides are videos captured from the screen.

It is more difficult to insert these into the TWiki pages than into the slides.

I uploaded mpeg video clips and added links such by clicking them

you can download and/or visualize the clips.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 3 of 17





















TWiki Slide Show
Next
VPython
VPython makes it easy to create and display these 3d objects.

VPython creates the scene in a separate windows and

  • Lets you move the viewpoint (3rd mouse button)
  • Lets you scale the image (2nd mouse button)
moveAndResize.png

and here is the video clip:

https://iotworkshop.africa/pub/AFNOG/VPythonAndTheVirtualWorld/virtualWorld.mpeg

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 4 of 17





















TWiki Slide Show
Next
VPython Doc
The documentation of VPython explains how to create and change the objects

VPythonDoc.png

You can find it at vpython.org

Now we will go through a few simple examples which will enable us to assemble the scene.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 5 of 17





















TWiki Slide Show
Next
Create a cylinder
First we must import the methods allowing to create the objects and then create the cylinder.
cylinder-1Code.png cylinder-1.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 6 of 17





















TWiki Slide Show
Next
The FutureWarning
When running the code you will see a warning:

futureWarning.png

It turns out that I did not have this problem on my older version of

Raspbian which runs a slightly older version of Python.

It must have appeared only with a very recent Python-2.7 version.

It is only a warning and does not prevent the program from running.

If it annoys you, you have 2 options:

  • Correct the code of VPython or
  • simply suppress the warning
The warning can be suppressed by the following code:

suppressWarning.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 7 of 17





















TWiki Slide Show
Next
Add a sphere
Now we want to add a sphere at position 0,0,0 and move the cylinder to the left of the x-axis.
cylinderAndSphereCode.png cylinderAndSphere.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 8 of 17





















TWiki Slide Show
Next
Change Size and Color
Next we want to make the cylinder longer but slimmer,

change the color of the sphere and make it real small.

sizeAndColorCode.png sizeAndColor.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 9 of 17





















TWiki Slide Show
Next
The Virtual Paper Sheet
Finally let’s add a virtual paper sheet in form of a very thin (in x-direction) box

simulating the paper sheet:

virtualPaperCode.png virtualPaper.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 10 of 17





















TWiki Slide Show
Next
Move the paper
Once the static part is done we have to figure out how to move the paper

(depending of the distance of the real paper to the distance detector)

and how to change its color (depending on the color found by the color sensor)

Let's first do this without reading the sensors by just displaying the paper at a certain

position before moving it on and by changing its color and displaying it for a time before

changing it.

paperMoveCode.png paperMove.png
and here is the corresponding video clip again:

https://iotworkshop.africa/pub/AFNOG/VPythonAndTheVirtualWorld/movePaper.mpeg

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 11 of 17





















TWiki Slide Show
Next
Change the Paper Color
paperColorCode.png virtualPaper.png
again, here is the video clip:

https://iotworkshop.africa/pub/AFNOG/VPythonAndTheVirtualWorld/colors.mpeg

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 12 of 17





















TWiki Slide Show
Next
Text in VPython
In our case it might be interesting to print the current distance to the paper in text form.
vPythonTextCode.png vpythonText.png
the video clip shows the result:

https://iotworkshop.africa/pub/AFNOG/VPythonAndTheVirtualWorldlabel.mpeg

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 13 of 17





















TWiki Slide Show
Next
A model of the distance sensor
This is the model of the ultrasonic distance sensor.

First the blue base plate is creates on which we have 2 cylinders

representing the loudspeaker and the microphone.

On top of each white cylinder I put a very thin black cylinder.

In addition we see the quartz implemented as a box

Understanding this code will allow you to easily create the model of the color sensor.

distanceSensorModelCode.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 14 of 17





















TWiki Slide Show
Next
Integrating the measurements
To be added:

  • Create a pi object connecting our program to the pigpiod daemon
  • Create a colorSensor instance
  • Create a usSensor instance (us stands for ultra-sonic)
  • Calibrate the colorSensor with black and white
In an endless loop:

  • Read the distance sensor
  • If the paper is close to the distance sensor, read the color
  • Adapt the distance and the color of the model paper

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 15 of 17





















TWiki Slide Show
Next
Color reading only close by
Why do we read the color only when the paper is close to the color sensor?

The color found by the sensor depends on the light intensity

reflected by the paper and this changes with distance


If we measure the color far away from the sensor little light will fall

onto the sensor and the color will come out dark.


Therefore put the paper close to the color sensor at first and keep the same

color when the paper is moving away from the sensor.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 16 of 17





















TWiki Slide Show
Next
Time to experiment
Enough lectures, enough talking!

It is time to experiment. Hopefully you now have the information needed to play with

  • the Python language
  • sensors and actuators
  • VPython to create realistic models
Of course 2 days are too short to go into detail of IoT sensors and actuators.

The Raspberry Pi offers you many more possibilities:

  • different hardware interfaces
    • I2C bus
    • SPI bus
    • camera interface ....
  • and of course you can write your IoT code in a different language

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 17 of 17





















First slide Previous End Presentation






























-- Uli Raich - 2018-04-25

Comments

I Attachment History Action Size Date Who Comment
PNGpng VPythonDoc.png r1 manage 97.5 K 2018-04-25 - 17:36 UliRaich  
Quicktime moviempeg colors.mpeg r1 manage 1244.0 K 2018-04-25 - 17:37 UliRaich  
PNGpng cylinder-1.png r1 manage 21.6 K 2018-04-25 - 17:35 UliRaich  
PNGpng cylinder-1Code.png r1 manage 10.1 K 2018-04-25 - 18:04 UliRaich  
PNGpng cylinderAndSphere.png r1 manage 10.2 K 2018-04-25 - 17:35 UliRaich  
PNGpng cylinderAndSphereCode.png r1 manage 11.8 K 2018-04-25 - 18:14 UliRaich  
PNGpng distanceSensorModelCode.png r1 manage 40.4 K 2018-04-25 - 18:34 UliRaich  
PNGpng futureWarning.png r1 manage 22.4 K 2018-04-25 - 18:04 UliRaich  
Quicktime moviempeg label.mpeg r1 manage 864.0 K 2018-04-25 - 17:38 UliRaich  
PNGpng moveAndResize.png r1 manage 21.5 K 2018-04-25 - 17:35 UliRaich  
Quicktime moviempeg movePaper.mpeg r1 manage 612.0 K 2018-04-25 - 17:39 UliRaich  
PNGpng paperColorCode.png r1 manage 58.5 K 2018-04-25 - 18:41 UliRaich  
PNGpng paperMove.png r1 manage 2.7 K 2018-04-25 - 18:29 UliRaich  
PNGpng paperMoveCode.png r1 manage 48.2 K 2018-04-25 - 18:29 UliRaich  
PNGpng scene-1.png r1 manage 16.4 K 2018-04-25 - 17:35 UliRaich  
PNGpng sizeAndColor.png r1 manage 6.6 K 2018-04-25 - 18:18 UliRaich  
PNGpng sizeAndColorCode.png r1 manage 19.9 K 2018-04-25 - 18:18 UliRaich  
PNGpng suppressWarning.png r1 manage 9.7 K 2018-04-25 - 18:04 UliRaich  
PNGpng vPythonTextCode.png r1 manage 71.2 K 2018-04-25 - 18:46 UliRaich  
PNGpng virtualPaper.png r1 manage 7.1 K 2018-04-25 - 18:21 UliRaich  
PNGpng virtualPaperCode.png r1 manage 29.7 K 2018-04-25 - 18:21 UliRaich  
Quicktime moviempeg virtualWorld.mpeg r1 manage 732.0 K 2018-04-25 - 17:39 UliRaich  
PNGpng vpythonText.png r1 manage 5.1 K 2018-04-25 - 18:50 UliRaich  
PNGpng vpythonText.png.png r1 manage 5.1 K 2018-04-25 - 18:46 UliRaich  

This topic: AFNOG > WebHome > Slides > VPythonAndTheVirtualWorld
Topic revision: r1 - 2018-04-25 - UliRaich
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback