Giter Site home page Giter Site logo

rpi-examples's Introduction

rpi-examples

This repository provides various examples for using peripheral devices such as sensors, buzzers, relays and add-on boards on Raspberry Pi single board computers written in popular programming languages C, C++, Python, etc. All examples are available under MIT license.

These examples are appropriate for beginners. Hopefully, they will encourage more developers to join the Raspberry Pi community and to help them get started easily with various peripheral devices for both professional and hobby and DIY projects.

Videos

Notes

If you are interested in running any of the examples for I2C written in C/C++ as a regular user (not root) perform the following steps:

  • Remove line "wiringPiSetup();" in "HTU21D_test.c"
  • Add your user in "i2c" group

Buzzer

C

Beep

Simple application to test if a piezo buzzer attached to pin 11 is working.

Install wiringPi and after that execute the following command to build the application:

cd buzzer/c/
gcc beep.c -o beep -lwiringPi -std=c99

Execute the following command to run the application:

sudo ./beep

Star Wars

Implementation of the Imperial March from Star Wars.

Install wiringPi and after that execute the following command to build the application:

cd buzzer/c/
gcc starwars.c -o starwars -lwiringPi -std=c99

Execute the following command to play the Imperial March:

sudo ./starwars

TSL2561

Install i2c tools:

sudo apt-get install i2c-tools

Enable i2c on Raspberry Pi with Raspian GNU/Linux distribution:

sudo raspi-config

Go to Advanced Options > A7 I2C and reboot the board

Verify that TSL2561 is detected on i2c address 39 on bus 1:

pi@raspberrypi:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- 39 -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

Build and run the source code

cd TSL2561/c/
make
./TSL2561_test

MAX44009 Ambient Light Sensor Module

Build and run the source code

cd MAX44009/c/
make
./MAX44009_test

The example written in the C programming language has been cotributed by Pixel_K.

PN532 NFC Module

  • Install Adafruit Python PN532:
sudo apt-get update
sudo apt-get install build-essential python-dev git
cd ~
git clone https://github.com/adafruit/Adafruit_Python_PN532.git
cd Adafruit_Python_PN532
sudo python setup.py install
  • Clone rpi-examples:
cd ~
git clone https://github.com/leon-anavi/rpi-examples.git
  • Save data to RFID/NFC card
cd ~/rpi-examples/PN532/python
sudo python rfid-save.py
  • Listen and scan for RFID/NFC cards
cd ~/rpi-examples/PN532/python
sudo python rfid-scan.py

rpi-examples's People

Contributors

hankb avatar leon-anavi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rpi-examples's Issues

Issue with TSL2561 Code

Hello Leon!

First of all, thank you for your example code - I've gotten a fair amount of mileage out of what I've worked with so far, very much appreciated!

I am however having an issue with the TSL2561 Flora Lux Sensor. I have tried both the code in example and the code in example-wiringpi with similar results. When I first ran the software, I got large numbers (i.e., 65535) for my lux value along with an Input/output error. This was because I had to change the address to the LOW value (hard coded on the Flora Lux - verified with I2CDetect). Now, however, I always receive 0. This is the case in both examples - example and example-wiringpi.

To try and do some high level debugging, I edited TSL2561_test.c again and printed out the return code for each function;
OPEN
SETGAIN
SETINTEGRATIONTIME
SENSELIGHT

Everything returns 0, which appears to be normal based upon what I'm seeing in the lower level code. I also tried playing with the gain, integration time and library auto gain, just to see if anything I did gave me a different value, but 0 on all values all the time.

Before I dive headfirst into your lower level code, is there anything you might suggest I look into? I looked at a few other examples to use, but I really much prefer going with your C code at this point, especially after the HTU21D code has proven to be so helpful!

Alright, thank you so much in advance for any assistance you might be able to provide!

Respectfully,
Marshall

I2C no need to be "root"

Hi,

In the sample for HTU21D, you can check I2C values without be root:

  • remove line "wiringPiSetup();" in "HTU21D_test.c"
  • add your user in "i2c" group

Enjoy ! :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.