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 script![]() Loops in bashYou can write
Example of an endless loop in bash![]() ![]() | ||||||||||||||||||||||||||||
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 correct![]() The test and assignment of the wave type![]() Bit 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:(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 preparation![]() Now the test program generating data for the DAC![]() StrobeNow 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: Strobe![]() Exiting 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 handler![]() Catching signals![]() | ||||||||||||||||||||||||||||
%SLIDESHOWEND% -- ![]() Comments | |||||||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||||||
< < | |||||||||||||||||||||||||||||
> > | Preparing data for the DAC | ||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
Line: 149 to 427 | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||||||
> > |
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
![]() Slide 1: Accessing the Real WorldLecture 7 | ||||||||
Deleted: | ||||||||
< < | Accessing the RPI remotely | |||||||
Deleted: | ||||||||
< < | Of course we can use the interfaces on the Raspberry Pi
to connect a screen, keyboard and mouse and use it
in stand-alone mode but we can also make use
of the PC resources and access it remotely.
There are several ways to access the RPI remotely:
The remote Desktop![]() Remote Desktop (2)When running the remote desktop you are working on the Raspberry Pi with the screen, keyboard and mouse replaced by the devices on the PC. You have the same functionality as if the screen was connected to the Pi’s HDMI port and keyboard and mouse were connected to the USB ports on the Pi.nfs the network file systemWith nfs you can mount part of the Pi’s file system tree onto your PC file system. This allows you access to the Pi’s files as if you were using a local disk. You cannot run any Rasberry Pi programs this way however. It is interesting if you cross-compile Pi programs on your PC, which will be immediately visible on the Pi.ssh the secure shellIn the case of ssh you have a single terminal window that is connected to a shell on the Pi. The command is: ssh userOnPi@piIPaddress Where piIPaddress can be the Pi’s IP address of hostname.If you specify the -X option you can run X-11 based programs where the X protocol is run over the ssh connection. ssh session exampleHere you see a screen dump from the PC with a remote terminal that started an emacs session on the Pi.![]() scpTo copy a file from the PC to the Pi this would be the command: scp myfile.c uli@raspberry10:exercises/solutions/exercise_2This will copy the file “myfile.c” into the sub-directory exercises/solutions/exercise_2 on my home directory on the Pi. Of course user uli must exist on raspberry10. Instead of specifying the machine name: raspberry10 you can also give its IP address. Compiling C programs for the Raspberry PiJust like Linux on the PC, Linux on the Raspberry Pi uses the GNU C compiler gcc. The
However, the code generator is different since now we compile for the ARM processor and not the Intel processor used on the PC Cross-Compilation for the PiAs explained in a previous lecture we can also compile C programs for the Raspberry Pi on the PC Linux system using a cross-compiler. The cross compiler we will use is named arm-linux-gnueabihf-gcc and it is part of the tools package![]() | |||||||
Access librariesAs we have already seen, the Raspberry Pi flat cable connector |
Line: 1 to 1 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
![]() Slide 1: Accessing the Real WorldLecture 7 | |||||||||||||||
Changed: | |||||||||||||||
< < | %SLIDESHOWEND% | ||||||||||||||
> > | Accessing the RPI remotely | ||||||||||||||
Changed: | |||||||||||||||
< < | -- ![]() | ||||||||||||||
> > | Of course we can use the interfaces on the Raspberry Pi
to connect a screen, keyboard and mouse and use it
in stand-alone mode but we can also make use
of the PC resources and access it remotely.
There are several ways to access the RPI remotely:
The remote Desktop![]() Remote Desktop (2)When running the remote desktop you are working on the Raspberry Pi with the screen, keyboard and mouse replaced by the devices on the PC. You have the same functionality as if the screen was connected to the Pi’s HDMI port and keyboard and mouse were connected to the USB ports on the Pi.nfs the network file systemWith nfs you can mount part of the Pi’s file system tree onto your PC file system. This allows you access to the Pi’s files as if you were using a local disk. You cannot run any Rasberry Pi programs this way however. It is interesting if you cross-compile Pi programs on your PC, which will be immediately visible on the Pi.ssh the secure shellIn the case of ssh you have a single terminal window that is connected to a shell on the Pi. The command is: ssh userOnPi@piIPaddress Where piIPaddress can be the Pi’s IP address of hostname.If you specify the -X option you can run X-11 based programs where the X protocol is run over the ssh connection. ssh session exampleHere you see a screen dump from the PC with a remote terminal that started an emacs session on the Pi.![]() scpTo copy a file from the PC to the Pi this would be the command: scp myfile.c uli@raspberry10:exercises/solutions/exercise_2This will copy the file “myfile.c” into the sub-directory exercises/solutions/exercise_2 on my home directory on the Pi. Of course user uli must exist on raspberry10. Instead of specifying the machine name: raspberry10 you can also give its IP address. Compiling C programs for the Raspberry PiJust like Linux on the PC, Linux on the Raspberry Pi uses the GNU C compiler gcc. The
However, the code generator is different since now we compile for the ARM processor and not the Intel processor used on the PC Cross-Compilation for the PiAs explained in a previous lecture we can also compile C programs for the Raspberry Pi on the PC Linux system using a cross-compiler. The cross compiler we will use is named arm-linux-gnueabihf-gcc and it is part of the tools package![]() | ||||||||||||||
Added: | |||||||||||||||
> > | Access librariesAs we have already seen, the Raspberry Pi flat cable connector and the cobbler + bread board, give access to external hardware though
Software accessOf course you can access the external hardware through the BCM-2837 interfaces and their registers directly, however, this is not for the faint-hearted (read the 200 page manual first!) The easier way to access these devices are ready made libraries giving you a simpler API for access To my knowledge there are 2 such libraries around (at least these are the most popular ones):How to download and installBoth libraries can be downloaded as git source archives, which allows you to have the very latest version and to keep your version up to date. git is a revision control system allowing many developers to work on the same project. You check out the current version, work on it and you can upload to the git server the modifications you made. You can also create a new code branch where you implement new functionality which may be specific to what you want to use the code for, or it may be a try to implement new options which may later be discarded or, in case everybody is interested in this new functionality it may be merged back into the main branch.Getting the LED blink program to workThe wiringPi library has included a few example programs to show its use. The most simple one is a program making a LED blink. WiringPi has its own numbering system for the GPIO pins:![]() Creating blink.cAs you would expect, wiringPi has its own include file which you must use in order to access the library: #include <wiringPi.h> On our systems we have installed this include file is in /usr/include on the Pi file system while the library itself is in /usr/lib As these are the standard positions for include files and libraries on a Linux system all we have to do in the Makefile is to add -lwiringPi to the LDLIBS macro.The C code of blink.c![]() The Makefile to build blink![]() Ohm's lawIf you consider that the LED has no resistance and the Raspberry Pi drives the GPIO pins with 3.3V and you connect as shown in the circuit diagram, then what is the current flowing through the LED?![]() WiringPi functionsThe library has functions to
WiringPi functions (2)
The gpio commandIn 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. %SLIDESHOWEND% -- ![]() | ||||||||||||||
Comments\ No newline at end of file | |||||||||||||||
Added: | |||||||||||||||
> > |
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
![]() Slide 1: Accessing the Real World |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Added: | ||||||||
> > |
![]() Slide 1: Accessing the Real WorldLecture 7 |