-
Notifications
You must be signed in to change notification settings - Fork 72
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
PatrickLang
wants to merge
15
commits into
rust-embedded-community:master
Choose a base branch
from
PatrickLang:raspi-example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+531
−0
Open
Raspi example #133
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a822a98
init example
chux0519 7224c33
fix: stroke color
chux0519 3846d90
feat: add image support
chux0519 100b403
add loop
chux0519 5813ea4
doc: add README
chux0519 807c671
Blank screen on SIGINT/SIGTERM to avoid image retention
PatrickLang b0b83dc
Use cross for easier build
PatrickLang a261da2
De-duplicate rust.raw
PatrickLang 0d33a5f
Gh build (#1)
PatrickLang 435029d
Merging in sample from chux0519/raspi-oled
PatrickLang f538749
Link to and improve README for RaspPi
PatrickLang 2cb1fc8
Moving to updated dependencies
PatrickLang d2330be
Finish updating dependencies
PatrickLang eea92ff
Add CircleCI build for examples/raspi
PatrickLang 053e87d
Remove GitHub CI
PatrickLang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
**/*.rs.bk |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../rust.raw |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit