Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspi example #133

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ fn HardFault(ef: &ExceptionFrame) -> ! {

```

### Raspberry Pi

A sample project is available under [examples/raspi](./examples/raspi)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

Suggested change
A sample project is available under [examples/raspi](./examples/raspi)
A sample project is available under [examples/raspi](./examples/raspi).


## License

Licensed under either of
Expand Down
14 changes: 14 additions & 0 deletions examples/raspi/.github/workflows/build-raspi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Build It
on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build for Raspberry Pi 2/3/4 32 bit
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --target armv7-unknown-linux-gnueabihf
2 changes: 2 additions & 0 deletions examples/raspi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
**/*.rs.bk
241 changes: 241 additions & 0 deletions examples/raspi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions examples/raspi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "raspi-oled"
version = "0.1.0"
authors = ["chux0519 <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
embedded-graphics = "0.6.0-alpha.2"
linux-embedded-hal = "0.2.2"
machine-ip = "0.2.1"
ssd1306 = "0.3.0-alpha.2"
ctrlc = { version = "3.0", features = ["termination"] }
72 changes: 72 additions & 0 deletions examples/raspi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# SSD1306 demo on Raspberry pi

This is a sample that uses the built-in I2C bus available in Linux on the Raspberry Pi B/2/3/4.

## Connections

This sample relies on the default [Raspberry Pi pinout](https://www.raspberrypi.org/documentation/usage/gpio/) for i2c:

| Pin | Description |
|-----|-------------------------------------|
| 1 | 3.3 v power |
| 3 | GPIO 2 (SDA) |
| 5 | GPIO 3 (SCL) |
| 6 | ground |


Some boards such as the [Adafruit OLED bonnet](https://www.adafruit.com/product/3531) use this same pinout if you want something ready to use without extra wiring or soldering.

## OS Configuration

If you're using Raspbian - [raspi-config](https://www.raspberrypi.org/documentation/configuration/raspi-config.md) has an option to enable I2C by default. If you're using another distro - do a quick search and you will probably find a solution to enable it.

Before running this sample, you can check that your OLED display is detected by installing `i2c-tools` from your distro, then running `i2cdetect -y 1`. The first connected SSD1306 will usually be at address `0x3c`. This sample assumes `0x3c`. If your device is at a different address, then you may need to modify the code for it to work.

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

## Building the code

The easiest way to build this sample is with [Cross](https://github.com/rust-embedded/cross).

```
cross build --release --target armv7-unknown-linux-gnueabihf
```

> That assumes Raspberry Pi 2/3/4 running a 32 bit kernel

After the build finishes, copy it to your Raspberry Pi

```
scp target/armv7-unknown-linux-gnueabihf/release/raspi-oled user@ip:/home/user
```

Then SSH to your Pi and run it

```
sudo ./raspi-oled
```

## It works!

Once the code is running, it will look like this :)

Commodity SSD1306 boards

![A Raspberry Pi hooked up to a yellow+blue OLED showing the Rust logo](./images/01.jpg)

![A Raspberry Pi hooked up to a yellow+blue OLED showing the IP and some shapes](./images/02.jpg)

Adafruit 128x64 OLED bonnet

![A Raspberry Pi hooked up to a yellow+blue OLED showing the IP and some shapes](./images/adafruit-oled.jpg)
Binary file added examples/raspi/images/01.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/raspi/images/02.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/raspi/images/adafruit-oled.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/raspi/rust.raw
Loading