Solutions to the exercises

This is the page to which the solutions will be uploaded. These will mainly consist of gzipped tar files which you can download and unpack.

For the exercise on Linux the are no solutions as these are simple Linux commands to be executed into the bash command interpreter.

  • Solutions to exercise 1: Linux Commands
    There are no solutions to this exercise. We simply try out a series of bash commands

  • Solutions to exercise 2: C programming:
    These are only the solutions to the exercises. Many more small example programs you find in the lecture page
    Lecture3: Introduction to C Programming
https://iotworkshop.africa/pub/Embedded_Systems/SolutionsToTheExercises/solEx2.tar.gz

  • Solutions to exercise 3: Programming Tools
    Even though there are no solutions to exercise3: Compilations Tools, here are a few Makefile examples nevertheless:
https://iotworkshop.africa/pub/Embedded_Systems/SolutionsToTheExercises/makeExamples.tar.gz

  • Solutions to the exercises on files, pipes and sockets
    These exercises have been skipped but I attach the solution codes nevertheless such that you can have a look at them and/or use them in a future course
https://iotworkshop.africa/pub/Embedded_Systems/SolutionsToTheExercises/communication.tar.gz

  • Solutions to exercise 4: Raspberry Pi
    There are no solutions to this exercise session because we only use programs that have already been written before.

  • Solutions to exercise 5: LED

    For the mygpio program, these are the tests you must perform in order to make the program safe against wrong input from the user
    • test if the user has given at least 2 arguments namely a string, which should be "read" or "write" and the pin number
      (argv may not be smaller than 3)
    • check if argv[1] is either "read" or "write". Use strcmp to accomplish this
    • if argv[1] is "read", make sure argc is exactly 3
    • if argv[1] is "write", make sure argc is exactly 4
    • convert the pin number from string to integer. You may be tempted to use atoi() but you must not, because atoi() does not check for conversion errors. Use strtol() instead.
    • Make sure the converted pin number is in the range 0..7
      For the "read" case we are done with our checks here
    • for the "write" case convert the logic level and make sure you get either 0 or 1

https://iotworkshop.africa/pub/Embedded_Systems/SolutionsToTheExercises/leds.tar.gz

  • Solutions to the exercises on switches

    These exercises have also been skipped because of lack of time but I attach the solution codes nevertheless such that you can have a look at them and/or use them in a future course
https://iotworkshop.africa/pub/Embedded_Systems/SolutionsToTheExercises/switches.tar.gz

  • Solutions to exercise 7: Stepping Motors

    In addition to the solutions to the stepping motor exercises I add the code written for the rotary encoder, which is a sort of a reverse stepping motor. Instead of sending a pulse sequence, you receive one and by interpreting it you can tell the relative angle the motor has reached. Here is the code:
https://iotworkshop.africa/pub/Embedded_Systems/SolutionsToTheExercises/rotaryEncoder.tar.gz

  • Solutions to the exercises on the DS18B20 1-wire digital temperature sensor

    The solutions make use of the device driver available for the DS18B20 in the Linux system. Since we had no time to look into the concepts of device drivers, this exercise has been left out. Here are the solutions, if you want to try for a future course:
https://iotworkshop.africa/pub/Embedded_Systems/SolutionsToTheExercises/ds18b20.tar.gz

  • Solutions to exercise 6: The DHT11 temperature and humidity sensor

    The code contains an example of how to write a shared library. You can collect all libraries for your course in a common directory (.g. /opt/ucc/lib) as you do for all corresponding include files (/opt/ucc/include). Then you make the directory of libraries globally known to the system by putting a file ucc.conf into /etc/ld.so.conf. ucc.conf simply contains the text /opt/ucc/lib. Finally you run the command sudo ldconf and /opt/ucc/lib will be added to the search path of shared libraries on the system.

  • Solutions to the exercises on light measurement

    Again the exercises have not been proposed during the course. They use the photo resistor available in the sensor kit but need a high value capacitor in addition. In these exercise the analogue value of resistance is not measured through an ADC but uses a capacitor which is charged over the resistance in the photo resistor. By measuring the time the capacitor needs to be charge to a level that switches the state of a gpio pin from low to high, the resistance and thus the light intensity can be measured.
    Again the solutions are available here:
https://iotworkshop.africa/pub/Embedded_Systems/SolutionsToTheExercises/photoResistor.tar.gz

  • Solutions to exercise 12: Reading the BMP180 temperature and barometric pressure sensor

    The manufacturer of the device provides an access library to the device which takes care of converting the raw data read from the sensor device into humanly readable values. The library must be adapted to the I2C access method used be the micro-controller to which the device is connected (in our case the Raspberry Pi). The solutions show how this is done, how to extract the documentation from the source code using the doxygen tool and how to use the library in your own programs.
https://iotworkshop.africa/pub/Embedded_Systems/SolutionsToTheExercises/bmp180.tar.gz

  • Solutions to exercise 8: Digital to Analogue conversion

    Many devices are controlled through analogue signal levels. A nice example of a device creating these signal levels is the MicroChip mcp4725, a 12 bit I2C based DAC. The solutions show examples of how to set a level and how to create wave forms.
    The frequency of the wave form is limited by the I2C access speed (normally 100 kBit/s). The chip is capable to go up to 3.4 MBits/s which however I have not tried. You would have to modify the bit rate in the driver. Up to you to find out how this is done

  • Solutions to exercise 10: a 2 line LCD Display

    Very often embedded systems do not have a keyboard, mouse and screen attached to them but they must live with more rudimentary (and much cheaper) input/output devices. Such a device is the 2-line display we have in our sensor collection. It is highly recommendable to write a shared library for the device because it can be used in many applications (see the nameDisplay, VoltMeter and MeteoStation we had at the Open Day).
    The solutions show how this is done, how the library is tested and how to include in-code documentation in doxygen format.

  • Solutions to exercise 11: Digital to Analogue Conversion

    Even more important than digital to analogue conversion is its counterpart: analogue to digital conversion (ADC). Even though we have a high precision 4 channel ADC in our kit of sensors (the ADS1115 16 bit ADC) we use the much simpler model: a PCF8591, 8 bit ADC, simply because the PCB on which this ADC is mounted, already contains a potentiometer, a photo resistor and a thermistor which which we can play.
    When used in conjunction with the 2-line LCD display it is easy to create a simple volt meter.

  • Solutions to exercise 9: the at24c32 EEPROM

    We have a little PCB with a ds1307 Real Time Clock and an at24c32 32kbit EEPROM on board. Both devices can be accessed through the I2C bus. These solutions show what needs to be done to read and write the EEPROM. Again the access routines are implemented in a shared library. In this code we do not use pigpio library calls for I2C access but use the device driver implemented for the Linux kernel directly.

  • Solutions to exercise 13: the ds1307 Real Time Clock

    These solutions show how to set the real time clock using a complex command line argument interface with getopt_long. Many of the Linux commands are implemented this way. The program, when called without parameters, shows the current date and time, with parameters it allows to set seconds, minutes, hours, day...

-- Uli Raich - 2017-10-14

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatgz bmp180.tar.gz r1 manage 244.1 K 2017-10-31 - 08:38 UnknownUser  
Unknown file formatgz communication.tar.gz r1 manage 0.1 K 2017-10-26 - 08:24 UnknownUser  
Unknown file formatgz ds18b20.tar.gz r1 manage 20.9 K 2017-10-31 - 08:10 UnknownUser  
Unknown file formatgz leds.tar.gz r1 manage 6.3 K 2017-10-26 - 11:50 UnknownUser  
Unknown file formatgz makeExamples.tar.gz r1 manage 1.7 K 2017-10-14 - 12:59 UnknownUser  
Unknown file formatgz photoResistor.tar.gz r1 manage 699.2 K 2017-10-31 - 08:30 UnknownUser  
Unknown file formatgz rotaryEncoder.tar.gz r1 manage 6.1 K 2017-10-26 - 11:53 UnknownUser  
Unknown file formatgz solEx2.tar.gz r1 manage 798.9 K 2017-10-14 - 12:53 UnknownUser  
Unknown file formatgz switches.tar.gz r1 manage 0.1 K 2017-10-31 - 08:03 UnknownUser  
Edit | Attach | Watch | Print version | History: r18 | r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r6 - 2017-10-31 - uli
 
  • Edit
  • Attach
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