Difference: ExerciseSheets (1 vs. 14)

Revision 142022-11-14 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Line: 9 to 9
 Connect your ESP32 to the PC using the micro USB cable and start thonny. Locate the shell window and check if you see the REPL prompt ">>>". If not, try to press <enter>. Make sure the shell window has the input focus. If this does not work, press the stop button. If this also doesn't help, press the reset button on the ESP32 CPU board.

Playing with REPL

  • print "Hello World!"
Changed:
<
<
  • calculate 127,9 * 157.6 * 17.2 /(3.5*2**4) 2**4 means 2 to the power of 4
    you may try to calculate e.g 2**4 separately first and check that you get the result expected
>
>
  • calculate 127,9 * 157.6 * 17.2 /(3.5*2**4), 2**4 means 2 to the power of 4
    you may try to calculate e.g 2**4 separately first and check that you get the result expected
 
  • continue experimenting with REPL

Hello World

Line: 79 to 76
  If the above is too simple for you, you may try to calculate the throwing parabola. Let's say, a stone is thrown at a speed of 30m/s and an angle of 30° with respect to ground. Calculate the trajectory of the stone until it hits the ground. You may define a function trajectory, taking as parameters the initial speed, the angle and the time resolution for which you want to calculate the stone positions.
Changed:
<
<
v_hor = v_initial * cos(angle)
>
>
v_hor = v_initial * cos(angle)
 v_ver = v_initial * sin(angle)
Deleted:
<
<
 x(t) = v_hor * t
Changed:
<
<
y(t) = v_ver * t - 1/2 * g * t**2
>
>
y(t) = v_ver * t - 1/2 * g * t**2
  Like this, you can easily calculate the trajectories for different angles and different initial speeds.
Line: 96 to 90
 tp_45 is the trajectory for 45 degrees.

Plotting is done as described above. When plotting several data files, use

Deleted:
<
<
 
replot "data_file.dat" with lines

in order to avoid deleting the previous plot.

Added:
>
>

Improving the program

This program can further be improved by plotting the same number of points for each parabola. To achieve this, we can first calculate the total flight duration until the object hits the ground again:

vt = 1/2*g*t**2, v => 1/2*g*t, t= 2*v/g

Then we calculate a fixed number of points (e.g. 50) for each parabola in a for loop.

Like this, we can easily see that for an angle of 30° and 60° the distance covered is the same. This is also true for 10° and 80° or 20° and 70°.

trajectories_V2.png

 

End of the second exercise session

Line: 182 to 184
 
META FILEATTACHMENT attachment="helloWorld.png" attr="" comment="" date="1665842121" name="helloWorld.png" path="helloWorld.png" size="73165" user="UliRaich" version="1"
META FILEATTACHMENT attachment="gnuplot_sin.png" attr="" comment="" date="1665866878" name="gnuplot_sin.png" path="gnuplot_sin.png" size="30601" user="UliRaich" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="exercises.odt" attr="" comment="" date="1666623199" name="exercises.odt" path="exercises.odt" size="210099" user="UliRaich" version="2"
>
>
META FILEATTACHMENT attachment="exercises.odt" attr="" comment="" date="1668441417" name="exercises.odt" path="exercises.odt" size="571588" user="UliRaich" version="3"
 
META FILEATTACHMENT attachment="trajectories.png" attr="" comment="" date="1666445815" name="trajectories.png" path="trajectories.png" size="58903" user="UliRaich" version="1"
META FILEATTACHMENT attachment="led_color_wheel.png" attr="" comment="" date="1666630102" name="led_color_wheel.png" path="led_color_wheel.png" size="169186" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="trajectories_V2.png" attr="" comment="" date="1668439751" name="trajectories_V2.png" path="trajectories_V2.png" size="69040" user="UliRaich" version="2"

Revision 132022-10-24 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Line: 6 to 6
 

First exercise session:

A bit of programming

Changed:
<
<
Connect your ESP32 to the PC using the micro USB cable and start thonny. Locate the shell window and check if you see the PEPL prompt ">>>". If not, try to press <enter>. Make sure the shell window has the input focus. If this does not work, press the stop button. If this also doesn't help, press the reset button on the ESP32 CPU board.
>
>
Connect your ESP32 to the PC using the micro USB cable and start thonny. Locate the shell window and check if you see the REPL prompt ">>>". If not, try to press <enter>. Make sure the shell window has the input focus. If this does not work, press the stop button. If this also doesn't help, press the reset button on the ESP32 CPU board.
 

Playing with REPL

  • print "Hello World!"
  • calculate 127,9 * 157.6 * 17.2 /(3.5*2**4) 2**4 means 2 to the power of 4
    you may try to calculate e.g 2**4 separately first and check that you get the result expected
Line: 46 to 46
 Write a script that prints "Hello World!" forever. You can stop the program with the red Stop button.

Write a program that prints "Hello World!" 7 times. Do this using a while loop and in a second program, using a for loop, Which of the programs is more elegant?

Added:
>
>

Too easy? Calculate the Fibonacci numbers

The Fibonacci numbers are defined as follows:

  • F(0) = 0
  • F(1) = 1
  • F(n) = F(n-1) + F(n-2)
Write a program that prints the Fibonacci series of numbers for n=10, n=20, n=30.
 

This is the end of the first exercise session

Second exercise session

MicroPython modules

Changed:
<
<
Modify the loop program in such a way that "Hello World!" is printed only every second. Import the utime module and make the program sleep for 1s after each print statement.
>
>
Modify the loop program in such a way that "Hello World!" is printed only every second. Import the time module and make the program sleep for 1s after each print statement.
  Import the sin function and the value of pi from the math module
Line: 64 to 71
 Create a sin_deg function which takes angles in units of degrees instead of radians. Print the angles and the sin values for 36 equidistant angle values.

You may copy/paste the result to a new editor window in thonny and save them to a file on the PC. Then you can plot the function using gnuplot.

Added:
>
>
  • run guplot
  • in gnuplot enter:
    plot "your_data_file.dat" with lines
  gnuplot_sin.png
Changed:
<
<

Calculating the throwing parabola

>
>

Too easy? Calculate the throwing parabola

 
Changed:
<
<
If the above is too simple for you, you may try to calculate the throwing parabola. Let's say, a stone is thrown at a speed of 30m/s and an angle of 30° with respect to ground. Calculate the trajectory of the stone until it hits the ground. You way define a function trajectory, taking initial speed, the angle and the time resolution for which you want to calculate the stone positions.
>
>
If the above is too simple for you, you may try to calculate the throwing parabola. Let's say, a stone is thrown at a speed of 30m/s and an angle of 30° with respect to ground. Calculate the trajectory of the stone until it hits the ground. You may define a function trajectory, taking as parameters the initial speed, the angle and the time resolution for which you want to calculate the stone positions.
  v_hor = v_initial * cos(angle)
Line: 85 to 94
 tp_10 is the trajectory for 10 degrees.

tp_45 is the trajectory for 45 degrees.

Added:
>
>
Plotting is done as described above. When plotting several data files, use

replot "data_file.dat" with lines

in order to avoid deleting the previous plot.

 

End of the second exercise session

Line: 102 to 117
 Use the function to implement a program that blinks an SOS: 3 short pulses, followed by 3 long pulses, followed by 3 short pulses, followed by a 2s pause. You may use a 200 ms delay for the short pulses and 700 ms delay for the long ones.

Reading the pushbutton

Changed:
<
<
Write a program that reads the push button state ever 100 ms and prints its state (pressed or released)
>
>
Write a program that reads the push button state every 100 ms and prints its state (pressed or released)
  Improve the program printing the state only when there was a state change.
Added:
>
>

Too easy? Change the light intensity on the LED using PWM

 
Changed:
<
<

Forth exercise session

>
>
Write a program that linearly increases the light intensity of the user programmable LED using Pulse Width Modulation ( PWM).

Fourth exercise session

 

Reading an analogue signal level from the slider potentiometer

  • Read the documentation of the ADC driver in the MicroPython manual
  • Connect the potentiometer to the triple base according to the table in Analogue Signals#PotConnections
  • Create an ADC object and make sure you set the attenuator to 11 dB
Changed:
<
<
  • Read the slider value every 100 ms and print its raw 12 bit value and print it.
>
>
  • Read the slider value every 100 ms and print its raw 12 bit value
 
  • Move the slider and observe the changes in the value

Controlling the rgb LED ring

Changed:
<
<
The LED ring consists of 7 WS2812B addressable and cascadable LEDs. Each rgb LED consists of 3 tiny single color LEDs emitting red, green and blue light. The color you finally see is the mixture between these color components. The MicroPython driver for this type of LED is called NeoPixel. The color is defined as a tuple with three 8 bit color component intensities. 8 bits means that you can have values in the range 0..255. Since the LEDs are extremely bright, please restrict the values to 0..31.
>
>
The LED ring consists of 7 WS2812B addressable and cascadable LEDs. Each rgb LED consists of 3 tiny single color LEDs emitting red, green and blue light. The color you finally see is the mixture between these color components. The MicroPython driver for this type of LED is called NeoPixel. The color is defined as a tuple with three 8 bit color component intensities. 8 bits means that you can have values in the range 0..255. Since the LEDs are extremely bright, please restrict the values to 0..31.
 
Changed:
<
<
Write a program trying to find out to which LED an LED number corresponds to. Where on the LED ring is LED0, LED1 ... Do this by lighting the LEDs one by one with only the red color component switched on. The green and blue are set to zero.
>
>
Write a program trying to find out to which physical LED an LED number corresponds to. Where on the LED ring is LED0, LED1 ...? Do this by lighting the LEDs one by one with only the red color component switched on. The green and blue are set to zero.
  Then change the color. Try all color combinations (31,0,0), (0,31,0), (0,0,31) but also (31,31,0), (31,0,31) ... Which colors do you get?

You can further modify the colors by changing the intensity values. For example: (12,27,5) Play around trying to generate as many different colors as you like.

You may have a look at the small project below and light the LEDs in the colors required by the project.

Added:
>
>

Too easy? Program the Color Wheel

Write a program that shows all the colors of the color wheel on the LEDs of the rgb LED ring. The color on the LEDs will slowly change from red to yellow to green … to magenta to red.

 
Added:
>
>
led_color_wheel.png
 

A small project

As a small project, we are going to combine the reading of the ADC and the control of the rgb LED ring. As we saw, the ADC delivers values between 0 and 4095 (12 bits). We can divide this range in 7 slices, corresponding to the 7 LEDs in the ring. For the lowest slice, the top LED will be lit. Then we go clockwise around the ring: the next LED lit will be to the right of the first one. For the highest slice, the middle LED will be lit.

Added:
>
>
In a first version, write a program that prints the LED number corresponding to the signal level on the slider. Make sure you get a value between 0 and 7.

Then light the LED you found with a single color (e.g. green)

 Very often, the color indicates the signal level: For low signal levels, we use "cold" colors (blue, cyan) for higher levels we use "hot" colors (magenta, red, white). The color for the top LED will therefore be blue, the color for the middle LED will be white.

Here is the color sequence:

Changed:
<
<
LED number color
1 blue
2 cyan
3 green
4 yellow
5 magenta
6 red
0 white
Read the slider value from the ADC, subdivide it into 7 slices and light the LED corresponding to the slide into which the ADC value falls. Use the color from the color table.
>
>
LED number color  
1 blue (0,0,31)
2 cyan (0,31,31)
3 green find the
4 yellow other
5 magenta colors
6 red yourself
0 white  
When lighting the LED, use the color from the color table.
  Here is the exercise sheet in odt format:
Line: 158 to 184
 
META FILEATTACHMENT attachment="gnuplot_sin.png" attr="" comment="" date="1665866878" name="gnuplot_sin.png" path="gnuplot_sin.png" size="30601" user="UliRaich" version="1"
META FILEATTACHMENT attachment="exercises.odt" attr="" comment="" date="1666623199" name="exercises.odt" path="exercises.odt" size="210099" user="UliRaich" version="2"
META FILEATTACHMENT attachment="trajectories.png" attr="" comment="" date="1666445815" name="trajectories.png" path="trajectories.png" size="58903" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="led_color_wheel.png" attr="" comment="" date="1666630102" name="led_color_wheel.png" path="led_color_wheel.png" size="169186" user="UliRaich" version="1"

Revision 122022-10-24 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Line: 81 to 84
  tp_10 is the trajectory for 10 degrees.
Changed:
<
<
tp_45 is the trajectories for 45 degrees.
>
>
tp_45 is the trajectory for 45 degrees.
 

End of the second exercise session

Line: 91 to 94
 Write a program that blinks the user programmable LED on the CPU card at a frequency of 1 Hz (500 ms on, 500 ms off)

Write a function that blinks the LED once with a delay that is passed as a parameter:

Added:
>
>
 
def blink_once(delay): 
Changed:
<
<
Test the function with a main program calling is with different delays.
>
>
Test the function with a main program calling it with different delays.
  Use the function to implement a program that blinks an SOS: 3 short pulses, followed by 3 long pulses, followed by 3 short pulses, followed by a 2s pause. You may use a 200 ms delay for the short pulses and 700 ms delay for the long ones.

Reading the pushbutton

Line: 102 to 106
  Improve the program printing the state only when there was a state change.
Changed:
<
<
>
>
 

Forth exercise session

Reading an analogue signal level from the slider potentiometer

  • Read the documentation of the ADC driver in the MicroPython manual
Line: 120 to 124
  You can further modify the colors by changing the intensity values. For example: (12,27,5) Play around trying to generate as many different colors as you like.
Changed:
<
<
Write a program that lights the top LED in blue and then lights the following LEDs in clockwise direction to :
  • blue (top LED)
  • cyan
  • green
  • yell low
  • magenta
  • red
  • the middle LED becomes white
#smallProject
>
>
You may have a look at the small project below and light the LEDs in the colors required by the project.

 

A small project

As a small project, we are going to combine the reading of the ADC and the control of the rgb LED ring. As we saw, the ADC delivers values between 0 and 4095 (12 bits). We can divide this range in 7 slices, corresponding to the 7 LEDs in the ring. For the lowest slice, the top LED will be lit. Then we go clockwise around the ring: the next LED lit will be to the right of the first one. For the highest slice, the middle LED will be lit.

Line: 158 to 156
 
META FILEATTACHMENT attachment="helloWorld.png" attr="" comment="" date="1665842121" name="helloWorld.png" path="helloWorld.png" size="73165" user="UliRaich" version="1"
META FILEATTACHMENT attachment="gnuplot_sin.png" attr="" comment="" date="1665866878" name="gnuplot_sin.png" path="gnuplot_sin.png" size="30601" user="UliRaich" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="exercises.odt" attr="" comment="" date="1666269925" name="exercises.odt" path="exercises.odt" size="147725" user="UliRaich" version="1"
>
>
META FILEATTACHMENT attachment="exercises.odt" attr="" comment="" date="1666623199" name="exercises.odt" path="exercises.odt" size="210099" user="UliRaich" version="2"
 
META FILEATTACHMENT attachment="trajectories.png" attr="" comment="" date="1666445815" name="trajectories.png" path="trajectories.png" size="58903" user="UliRaich" version="1"

Revision 112022-10-23 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Line: 30 to 30
  Assign again 2 values to 2 variables a and b with a being bigger than b . In your program, check if a is equal, bigger or smaller than b. Modify the values you assign to a and b, with b now bigger than a and try again.
Added:
>
>
In the lectures, we used the "<" and the ">" conditions to find out, if the value in the variable a is bigger, smaller or equal to the value in variable b. Can you modify the program using "<" and "!=" to find out?
 What happens if you test:
if a:
   print("yes")

Revision 102022-10-22 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Line: 61 to 61
 You may copy/paste the result to a new editor window in thonny and save them to a file on the PC. Then you can plot the function using gnuplot.

gnuplot_sin.png

Added:
>
>

Calculating the throwing parabola

If the above is too simple for you, you may try to calculate the throwing parabola. Let's say, a stone is thrown at a speed of 30m/s and an angle of 30° with respect to ground. Calculate the trajectory of the stone until it hits the ground. You way define a function trajectory, taking initial speed, the angle and the time resolution for which you want to calculate the stone positions.

v_hor = v_initial * cos(angle)

v_ver = v_initial * sin(angle)

x(t) = v_hor * t

y(t) = v_ver * t - 1/2 * g * t**2

Like this, you can easily calculate the trajectories for different angles and different initial speeds.

trajectories.png

tp_10 is the trajectory for 10 degrees.

tp_45 is the trajectories for 45 degrees.

 

End of the second exercise session

Line: 138 to 157
 
META FILEATTACHMENT attachment="helloWorld.png" attr="" comment="" date="1665842121" name="helloWorld.png" path="helloWorld.png" size="73165" user="UliRaich" version="1"
META FILEATTACHMENT attachment="gnuplot_sin.png" attr="" comment="" date="1665866878" name="gnuplot_sin.png" path="gnuplot_sin.png" size="30601" user="UliRaich" version="1"
META FILEATTACHMENT attachment="exercises.odt" attr="" comment="" date="1666269925" name="exercises.odt" path="exercises.odt" size="147725" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="trajectories.png" attr="" comment="" date="1666445815" name="trajectories.png" path="trajectories.png" size="58903" user="UliRaich" version="1"

Revision 92022-10-20 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Line: 129 to 125
 
0 white
Read the slider value from the ADC, subdivide it into 7 slices and light the LED corresponding to the slide into which the ADC value falls. Use the color from the color table.
Added:
>
>
Here is the exercise sheet in odt format:

https://iotworkshop.africa/pub/AFNOG/ExerciseSheets/exercises.odt

 -- Uli Raich - 2022-10-14

Comments

Line: 137 to 137
 
META FILEATTACHMENT attachment="helloWorld.png" attr="" comment="" date="1665842121" name="helloWorld.png" path="helloWorld.png" size="73165" user="UliRaich" version="1"
META FILEATTACHMENT attachment="gnuplot_sin.png" attr="" comment="" date="1665866878" name="gnuplot_sin.png" path="gnuplot_sin.png" size="30601" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="exercises.odt" attr="" comment="" date="1666269925" name="exercises.odt" path="exercises.odt" size="147725" user="UliRaich" version="1"

Revision 82022-10-20 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Line: 64 to 67
 

End of the second exercise session

Added:
>
>

Third exercise session

 

Programming the user LED on the CPU card

Write a program that blinks the user programmable LED on the CPU card at a frequency of 1 Hz (500 ms on, 500 ms off)

Line: 81 to 86
 Improve the program printing the state only when there was a state change.

Added:
>
>

Forth exercise session

 

Reading an analogue signal level from the slider potentiometer

Line: 105 to 111
 
  • magenta
  • red
  • the middle LED becomes white
Added:
>
>
#smallProject

A small project

As a small project, we are going to combine the reading of the ADC and the control of the rgb LED ring. As we saw, the ADC delivers values between 0 and 4095 (12 bits). We can divide this range in 7 slices, corresponding to the 7 LEDs in the ring. For the lowest slice, the top LED will be lit. Then we go clockwise around the ring: the next LED lit will be to the right of the first one. For the highest slice, the middle LED will be lit.

Very often, the color indicates the signal level: For low signal levels, we use "cold" colors (blue, cyan) for higher levels we use "hot" colors (magenta, red, white). The color for the top LED will therefore be blue, the color for the middle LED will be white.

Here is the color sequence:

LED number color
1 blue
2 cyan
3 green
4 yellow
5 magenta
6 red
0 white
Read the slider value from the ADC, subdivide it into 7 slices and light the LED corresponding to the slide into which the ADC value falls. Use the color from the color table.
  -- Uli Raich - 2022-10-14

Revision 72022-10-17 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Line: 84 to 80
  Improve the program printing the state only when there was a state change.
Changed:
<
<
# Session 4
>
>
 

Reading an analogue signal level from the slider potentiometer

Added:
>
>
  • Read the documentation of the ADC driver in the MicroPython manual
  • Connect the potentiometer to the triple base according to the table in Analogue Signals#PotConnections
  • Create an ADC object and make sure you set the attenuator to 11 dB
  • Read the slider value every 100 ms and print its raw 12 bit value and print it.
  • Move the slider and observe the changes in the value

Controlling the rgb LED ring

The LED ring consists of 7 WS2812B addressable and cascadable LEDs. Each rgb LED consists of 3 tiny single color LEDs emitting red, green and blue light. The color you finally see is the mixture between these color components. The MicroPython driver for this type of LED is called NeoPixel. The color is defined as a tuple with three 8 bit color component intensities. 8 bits means that you can have values in the range 0..255. Since the LEDs are extremely bright, please restrict the values to 0..31.

Write a program trying to find out to which LED an LED number corresponds to. Where on the LED ring is LED0, LED1 ... Do this by lighting the LEDs one by one with only the red color component switched on. The green and blue are set to zero.

Then change the color. Try all color combinations (31,0,0), (0,31,0), (0,0,31) but also (31,31,0), (31,0,31) ... Which colors do you get?

You can further modify the colors by changing the intensity values. For example: (12,27,5) Play around trying to generate as many different colors as you like.

Write a program that lights the top LED in blue and then lights the following LEDs in clockwise direction to :

  • blue (top LED)
  • cyan
  • green
  • yell low
  • magenta
  • red
  • the middle LED becomes white
 
Changed:
<
<
-- [[Main.U][ U liRaich -

2022-10-14]]

>
>
-- Uli Raich - 2022-10-14
 

Comments

Revision 62022-10-16 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Line: 67 to 67
 

End of the second exercise session

Added:
>
>

Programming the user LED on the CPU card

 
Changed:
<
<
-- Uli Raich - 2022-10-14
>
>
Write a program that blinks the user programmable LED on the CPU card at a frequency of 1 Hz (500 ms on, 500 ms off)

Write a function that blinks the LED once with a delay that is passed as a parameter:

def blink_once(delay): 

Test the function with a main program calling is with different delays.

Use the function to implement a program that blinks an SOS: 3 short pulses, followed by 3 long pulses, followed by 3 short pulses, followed by a 2s pause. You may use a 200 ms delay for the short pulses and 700 ms delay for the long ones.

Reading the pushbutton

Write a program that reads the push button state ever 100 ms and prints its state (pressed or released)

Improve the program printing the state only when there was a state change.

# Session 4

Reading an analogue signal level from the slider potentiometer

-- [[Main.U][ U liRaich -

2022-10-14]]

 

Comments

Revision 52022-10-15 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Line: 43 to 45
  Write a program that prints "Hello World!" 7 times. Do this using a while loop and in a second program, using a for loop, Which of the programs is more elegant?

This is the end of the first exercise session

Added:
>
>
 

Second exercise session

Added:
>
>

MicroPython modules

Modify the loop program in such a way that "Hello World!" is printed only every second. Import the utime module and make the program sleep for 1s after each print statement.

Import the sin function and the value of pi from the math module

from math import sin,pi

Remember that the sin function takes its values in units of radians. The angle values for a complete sin period will range 0 .. 2*pi. Print the angles and the sin values for a full sin period using 30 equidistant angle values. (x and sin(x)).

Creating and using your own function

Create a sin_deg function which takes angles in units of degrees instead of radians. Print the angles and the sin values for 36 equidistant angle values.

You may copy/paste the result to a new editor window in thonny and save them to a file on the PC. Then you can plot the function using gnuplot.

gnuplot_sin.png

End of the second exercise session

  -- Uli Raich - 2022-10-14
Line: 52 to 75
 
<--/commentPlugin-->

META FILEATTACHMENT attachment="helloWorld.png" attr="" comment="" date="1665842121" name="helloWorld.png" path="helloWorld.png" size="73165" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="gnuplot_sin.png" attr="" comment="" date="1665866878" name="gnuplot_sin.png" path="gnuplot_sin.png" size="30601" user="UliRaich" version="1"

Revision 42022-10-15 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

Changed:
<
<

A bit of programming

>
>

First exercise session:

A bit of programming

  Connect your ESP32 to the PC using the micro USB cable and start thonny. Locate the shell window and check if you see the PEPL prompt ">>>". If not, try to press <enter>. Make sure the shell window has the input focus. If this does not work, press the stop button. If this also doesn't help, press the reset button on the ESP32 CPU board.
Changed:
<
<

Playing with REPL

>
>

Playing with REPL

 
  • print "Hello World!"
  • calculate 127,9 * 157.6 * 17.2 /(3.5*2**4) 2**4 means 2 to the power of 4
    you may try to calculate e.g 2**4 separately first and check that you get the result expected
  • continue experimenting with REPL
Changed:
<
<

Hello World

>
>

Hello World

  Instead of working on the shell window, we will now write a Python script (a small program). For this to work, select File -> New. This will create an editor window named <untitled>. Save this empty program to the disk on your PC. Select File -> Save, select "This Computer" give it a file name (e.g. hello.py) and press "OK". The window title changes to hello.py.

Now enter

print("Hello World!")
Changed:
<
<
Finally, run the program by pressing the green button with the white triangle. You should see "Hello World!" printed in the shell window.
>
>
Finally, run the program by pressing the green button with the white triangle. You should see "Hello World!" printed in the shell window. This is what you should get:

helloWorld.png

Some Arithmetic

Assign 2 values to 2 variables a and b. Calculate the sum, the difference, the product and the division and print the results. Start assigning integer values. Try integer and float division.

Then assign float values and try again.

Conditions

Assign again 2 values to 2 variables a and b with a being bigger than b . In your program, check if a is equal, bigger or smaller than b. Modify the values you assign to a and b, with b now bigger than a and try again.

What happens if you test:

if a:
   print("yes")
else:
   print("No")

Try this with a being assigned to zero and a being assigned to 7. What do you conclude?

Loops

Write a script that prints "Hello World!" forever. You can stop the program with the red Stop button.

Write a program that prints "Hello World!" 7 times. Do this using a while loop and in a second program, using a for loop, Which of the programs is more elegant?

This is the end of the first exercise session

Second exercise session

  -- Uli Raich - 2022-10-14

Comments

<--/commentPlugin-->
\ No newline at end of file
Added:
>
>
META FILEATTACHMENT attachment="helloWorld.png" attr="" comment="" date="1665842121" name="helloWorld.png" path="helloWorld.png" size="73165" user="UliRaich" version="1"

Revision 32022-10-15 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

A bit of programming

Connect your ESP32 to the PC using the micro USB cable and start thonny. Locate the shell window and check if you see the PEPL prompt ">>>". If not, try to press <enter>. Make sure the shell window has the input focus. If this does not work, press the stop button. If this also doesn't help, press the reset button on the ESP32 CPU board.

Added:
>
>

Playing with REPL

 
  • print "Hello World!"
Changed:
<
<
>
>
  • calculate 127,9 * 157.6 * 17.2 /(3.5*2**4) 2**4 means 2 to the power of 4
    you may try to calculate e.g 2**4 separately first and check that you get the result expected
  • continue experimenting with REPL

Hello World

Instead of working on the shell window, we will now write a Python script (a small program). For this to work, select File -> New. This will create an editor window named <untitled>. Save this empty program to the disk on your PC. Select File -> Save, select "This Computer" give it a file name (e.g. hello.py) and press "OK". The window title changes to hello.py.

Now enter

print("Hello World!")

Finally, run the program by pressing the green button with the white triangle. You should see "Hello World!" printed in the shell window.

 -- Uli Raich - 2022-10-14

Comments

Revision 22022-10-15 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="ASP2022"

Exercises

A bit of programming

Changed:
<
<
Connect your ESP32 to the PC using the micro USB cable
>
>
Connect your ESP32 to the PC using the micro USB cable and start thonny. Locate the shell window and check if you see the PEPL prompt ">>>". If not, try to press <enter>. Make sure the shell window has the input focus. If this does not work, press the stop button. If this also doesn't help, press the reset button on the ESP32 CPU board.
  • print "Hello World!"
 -- Uli Raich - 2022-10-14

Comments

Revision 12022-10-14 - UliRaich

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="ASP2022"

Exercises

A bit of programming

Connect your ESP32 to the PC using the micro USB cable

-- Uli Raich - 2022-10-14

Comments

<--/commentPlugin-->
 
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