Hot answers tagged

20

Checking at configure/compile time for the features your code depends upon is the way to go. Checking for specific devices is problematic because avoiding false-positives is virtually impossible (someone could lie to you deliberately even with little effort) and the aim of such checks is to answer the question: "can I build here? If yes what code path should ...


18

On a computer you write to a specified 'memory address'. This address is recognised by the system as a hardware address, and the appropriate hardware receives or sends the appropriate value. Most hardware systems have many different registers that can be set or read. Some might have a few, some might have many. These registers will be grouped into a ...


15

You need to put a ./ in front of a.out in order to execute that: When you type the name of a program such as a.out the system looks for the file in your PATH. On my system, PATH is set to /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games Yours is probably similar. To check, enter ...


14

you should type: ./a.out if your file is in the current directory. also, you might check if executable bit is set with ls -al a.out and if not, set it using chmod +x a.out however, most compilers will set executable bit for you automagically.


13

You can read the file /sys/class/thermal/thermal_zone0/temp, as specified in this answer. There it's about measuring from the command line, and the file is read with cat. But you should be able to just open the file in C. The temperature is returned in milli-degrees Centigrade and as ASCII numbers. Perhaps like this, not tested :) FILE *temperatureFile; ...


13

Do NOT use nano (or another text editor to put your code into) with root/sudo permissions (ie. do not edit with sudo nano, only use nano) if all you are doing is personal stuff that does not need superuser permissions. Answer To compile from the command line (assuming yourcode.c is the name of your C file, and program the name of the resulting program ...


13

Yes, you can develop elsewhere before deploying to the Pi. However because the Pi is a different Architecture if you compile with your native compiler, your code wont be executable on the Pi. This can be solved by using a cross-compiler. Essentially this is a second GCC compiler on your system which uses the ARM toolchain for compiling. More information ...


13

I wrote a very simple kernel years ago, and ran it on a 386. I haven't done bare metal programming in years, but in broad terms you need to write some assembler code that will: disable interrupts during the boot process if the Pi has a memory controller, you'll need to set that up set up a timer tick configure the interrupt controller set up a stack so ...


12

I haven't looked at your code in depth, but it seems to me you're on the right track. Make sure that: The _start symbol is indeed the one used when compiling & linking your assembly file and your C file (and that main() isn't used instead) When calling main(), you need to use the C calling convention: push on the stack the address of the instruction ...


12

Mechanical buttons and switches can suffer from switch bounce where they toggle rapidly between open and closed for several milliseconds. You can try debouncing the button/switch in software or hardware. Probably simplest in software. If the level changes (on to off, or off to on) wait x milliseconds and read the gpio again. If it is still in the new ...


11

This depends on what libraries you wish to link your code with. If you are using the Raspbian images, the architecture is "armhf" and the compilation flags are: -march=armv6 -mfpu=vfp -mfloat-abi=hard If you are compiling for Debian "armel" arch, the compilation flags are different.


11

There is no official library There are several options. I usually use http://wiringpi.com. This is used for the gpio utility included in recent Raspbian releases. Joan's pigpio library is at https://github.com/joan2937/pigpio and she also has Python wrappers. If you want to use sockets or a daemon this is recommended and has good support for hardware and ...


9

The RPI ARM core is an ARM 1176jzf-S, the suitable flags should then be -march=armv6zk -mcpu=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp Drop the -mfloat-abi=hard -mfpu=vfp when on a soft float distro. These flags can be found by running gcc -mcpu=native -march=native -Q --help=target on gcc >= 4.7`


8

I found that this set should be the optimal: -march=armv6 -mfloat-abi=hard -mfpu=vfp (the -mfloat-abi=hard, of course only when you use an armhf distro)


8

Take the time to read Jack Ganssle's debouncing guide. The first page illustrates the problem in great detail, and the second how to deal with it in hardware or software. There isn't a 'perfect' debounce method, but there are a lot of bad ones! This is a problem you will come across repeatedly if interfacing software with switches, so it's worth taking ...


7

I have never tried to do this no the RPi, but I have on the Arduino platform several times, and I have used something along the lines of this Arduino code. Note you will have to rewrite a function similar to this for whatever language you are using: unsigned long last_interrupt_time = 0; void my_interrupt_handler() { unsigned long interrupt_time = ...


6

I want to modify the distro according to my needs. [...] What about the source for the actual distro? Is it all there? Am I insane? The distro has sources, but these are either the same as or slightly patched versions of the original sources -- a distro does not really contain any original software per se (discounting the package manager), it is just an ...


6

That example from elinux uses memory-mapped IO. The kernel also exports a user space interface via /sys/class/gpio,1 which is also documented on elinux. Working in C you would use low level read()/write() instead of echo, obviously. Don't use higher level stream based functions. Some programmers become a bit upset when told to use a file interface for ...


6

you should replace #define PIN RPI_GPIO_P1_7 with #define PIN RPI_GPIO_P1_07 (see the '0' before '7' ?)


5

First and foremost: If I were in your shoes, I would stay away from Wiegand in general!!! Why: Wiegand is a swipecard protocol developed in the 1980s. It does not use any form of clock signal or speed indication, the data timing is done based on the last bit that was transferred + the Wiegand delay time. This is a disadvantage but does not make it ...


5

That should be possible in Java, as referenced here. The library which is used is called rpi-gpio-java and is available at this URL. As stated in the notes, to make it work, please make sure your application is run as root. Note: Above project rpi-gpio-java is no longer available on google code. Alternate option is PI4J


5

command to run code in /etc/rc.local Three things to remember when putting commands in rc.local: Don't use sudo, because the script is run as root anyway. Unless the command exits quickly, it must fork to the background. This is accomplished by adding & to the end: mycommand & $PATH may not be set. This is a list of directories where the shell ...


5

/opt/vc/bin/vcgencmd measure_temp This returns the same thing as reading /sys/class/thermal, i.e., the core temp. Reading the /sys file is preferable programmatically because it is just a sequence of open/read system calls, instead of a fork/execute plus a bunch of open/read/write with pipes. How would I read the GPU temperature aswell? The BCM2835/6 ...


5

To set a pin numbering scheme you use one of four Setup functions: int wiringPiSetup (void); int wiringPiSetupGpio (void); int wiringPiSetupPhys (void); int wiringPiSetupSys (void); To use BCM GPIO numbering you would replace you would use wiringPiSetupGpio(void); and modify the pin numbers in your code appropriately.


4

What you are trying to achieve is almost impossible using operating system. It's really hard to have some hard real time user space mechanism inside operating system. You can try with some RT systems (I don't know if there are some RPi ports) or real time application interface (RTAI, Xenomai, RT Linux) and write some RT module. nanosleep() suspends the ...


4

I can confirm that SDL_mixer works on the pi. I am working on a platform game and use SDL for graphics and sound. My sounds are in the ogg format, but SDL_mixer promises mp3 support as well. I have raspbian, every SDL package I needed I could install from the repositories. Btw, the same game runs well and with sound on 64 bit linux too (at least Ubuntu and ...


4

The answer Yes it's safe. Judging from the source code of the library, it doesn't cache the values but reads them each time you call digitalRead function so it should work as expected. Documentation It isn't really documented in the wiringPi documentation but at least the documentation also doesn't say it's forbidden (for example for digitalWrite there ...


4

First question MAXTIMINGS means how many databits that the sensor sends is going to be read and stored (note that acording to the datasheet, it should send 40 bits in response). In order to understand this, you have to first understand how DHT22 is sending it's data to the host computer. It uses one wire, where host sends start signal: bcm2835_gpio_write(...


4

I misunderstood your question initially. Here is some C code that, when run, will record raw PCM data. You must pipe this to another program or lots of gibberish will be printed to the console. /* Use the newer ALSA API */ #define ALSA_PCM_NEW_HW_PARAMS_API #include <alsa/asoundlib.h> int main() { long loops; int rc; int size; ...


4

If you are looking for something comparable to Arduino, consider looking at WiringPi. WiringPi is an Arduino wiring-like library written in C and released under the GNU LGPLv3 license. The code example looks very similar to code written for the Arduino. You could also take a look at the bcm2835 library. The example code looks pretty simple. Just some ...


Only top voted, non community-wiki answers of a minimum length are eligible