Line: 1 to 1 | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Slide 1: Accessing the Real World | |||||||||||||||||||||||||||||
Line: 63 to 63 | |||||||||||||||||||||||||||||
in this new functionality it may be merged back into the main branch.
| |||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||
> > | Our use of gitWe do not want to develop the code but just use it. In this case we decide, where in our file system tree we want to install the source code of the library and then we download it with git clone git://git.drogon.net/wiringPi This will download the source code which we will have to compile which is done with ./build. This is a shell script! Have a look to see if you can understand what it does. In order to keep the library up to date we go to the wiringPi directory just created and we type: git pull This will update the source code to the latest version Here is the installation manual of wiringPi. | ||||||||||||||||||||||||||||
Getting the LED blink program to workThe wiringPi library has included a few example programs to show its use. | |||||||||||||||||||||||||||||
Line: 74 to 100 | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||
> > |
| ||||||||||||||||||||||||||||
Creating blink.cAs you would expect, wiringPi has its own include file | |||||||||||||||||||||||||||||
Line: 131 to 159 | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||
> > | A bit more on bash scriptsAs explained before bash provides it own programming language with
A bash script to setup the PisDuring the weekend I wanted to install the latest version of the wiringPi library from git on all 15 Raspberry Pis in the lab. I needed to
A bash script to setup the Pis (2)
... a lot of workThis is a lot of typing! The solution: a shell script! The shell script can only be executed by root because only theroot user can create directories in /opt How to check if we are root? A conditional statement in the script! The rest of the scriptLoops in bashYou can write
Example of an endless loop in bashYou can also read command line arguments just like you do it in C: | ||||||||||||||||||||||||||||
The gpio command | |||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||
< < | In addition to the library functions a new command: gpio is provided. This can be used to set gpio pins from bash It has however many more options. Look them up in its man page. | ||||||||||||||||||||||||||||
> > | There is the gpio command, which is part of wiringPi.
It has many options. Please have a look at its man page!
One option allows to read and write GPIO pins:
gpio write $PIN $ON_OFF
If PIN is 0 and ON_OFF is 1 then the LED connected to GPIO pin 0 will go on.
A bit more on C programmingWe have just seen the very basics of C programming and we need to learn a bit more about the libraries we can use Here we will look at
String handling functionsThere is a series of functions to
Treating command line argumentsConsider a wave generator where the user can choose the type of waveform using command line arguments. His options are:
---++ First check it the number of arguments is correctThe test and assignment of the wave typeBit handling functionsWe need to learn a few bit handling functions before being able to prepare the data for the DAC:| : bitwise or & : bitwise and data += 5 <=> data = data + 5 data |= 5 <=> data = data | 5 ~data: invert all bits in data data >> 4 all bits in data are shifted right by 4 data << 4 all bits in data are shifted left by 4 ---++Writing data to a DACImagine a 12 bit digital to analogue converter with the following register outline: The 12 bit data must be written 4 bits at a time to registers which are selected by the RS bits. The lowest significant digit goes to register 0(both RS bits zero) The medium significant digit to register 1 (RS=01) And the highest significant digit to register 2 (RS=01) To strobe the data into the register the strobe line must see a low to high transition The DACWe have a 12 bit DAC, which creates signal levels from 0V to Vcc What is the max. number this DAC can take in decimal and in hex? What is the signal resolution in This is Physics!Preparing data for the DACRemember the bit layout of the DAC register?We must write the
DAC preparationWrite a function which prepares a byte for the DAC The function takes 3 arguments:
What will be the result if you want to write 5 to register to the middle nibble? Solution: DAC preparationNow the test program generating data for the DACStrobeNow create a strobe function which takes DAC data (including the register bits) and generates a strobe signal on the STR line without touching the other bits With a correctly prepared data and register byte this will write the data to the correct register within the DACSolution: StrobeExiting a program gracefullyWhen we have a program like our blink program, then the only way to exit the endless loop is a ^C which will leave the LED in an unknown state. Is there a way to exit the program gracefully and to make sure the LED is always off once the program exits?Yes, there is!Killing the programWhen we kill the program with ^C, a signal (SIGINT) is sent to it which normally results in a brutal stop of the program. It is however possible to capture the signal and do some cleanup before the program finally exits.Signal handlerCatching signals | ||||||||||||||||||||||||||||
%SLIDESHOWEND% -- Uli Raich - 2017-09-27 Comments | |||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||
< < | |||||||||||||||||||||||||||||
> > | Preparing data for the DAC | ||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
Line: 149 to 427 | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||
> > |
|