Git Product home page Git Product logo

charloop's Introduction

charloop

An audio loop recorder for raspberry pi.

App

Soft Power Integration

These are the things the app is resposible for doing, in order to integrate with the soft power controller.

  1. Set pin 8 (RSTOPPED) HIGH. It should already be high because it's used by the UART to transmit. But this keeps it high until the raspi is very nearly shutdown.

  2. Set pin 12 (RBOOTED) HIGH. This will tell the soft power controller that the raspi has fully booted.

  3. Read pin 13 (SHUTDOWN). On HIGH, shut the raspi down.

  4. Read pins 10 (BATTERY STATUS DATA) and 11 (BATTERY STATUS CLOCK) to get the current battery level.

Dev

npm run watch
npm run client:start
npm run server:start

Production

npm run build

Raspberry Pi

  1. Download the Lite version of Raspbian and copy to an SD card. You want the Lite version because it comes with a lot less crap and we can just install what we need instead.

  2. Set up your raspberry pi.

  3. Install these packages:

    apt-get install vim git
    
  4. Install node (might need to change the wget URL here to a newer version):

    wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash
    # you might need to re-login here to get nvm in your path
    nvm install stable
    # this installed version 8.5.0 for me
    
  5. Make sure the user you're running as is a member of the gpio group:

    usermod -aG gpio username
    

Rotary Encoder

The rotary encoder I have (https://www.adafruit.com/product/377) has two leads for the push-button and three for the rotary encoder. Apparently the three rotary encoder pins use Gray code.

Pinout

 button   button
+--|---------|--+
|               |
|               |
|               |
+--|----|----|--+
   L   GND   R

Gray Code

I'm not sure if this is really Gray code. It's just what I figured out messing around with the encoder. I have my L and R pins set high initially. This is the process I used for reading the code from the encoder:

  1. Both pins start high and will remain high until the encoder is turned.
  2. One pin goes low: a turn has been initiated (it doesn't matter which pin goes low)
  3. Both pins are low: about to get the direction the encoder turned.
  4. One pin goes high:
    • If L goes high, it's a clockwise turn
    • If R goes high, it's a counter-clockwise turn
  5. Both pins will go high again and everything resets.

Here are graphs of the patterns. You'll notice that they both pins start and end high; the reset state.

Clockwise turn

L / -__--
R / --__-

States

L1, R1
L0, R1
L0, R0
L1, R0
L1, R1

Counter-clockwise turn

L / --__-
R / -__--

States

L1, R1
L1, R0
L0, R0
L0, R1
L1, R1

This lets you build a state machine that works with rpio's polling mechanism, where the direction is read at the end, just before both pins go high again.

TFT Display

  1. These are the pin connections I used:

    Description TFT Pin Raspi Pin
    TFT Data Out (MISO) 33 21
    Clock (SCLK) 37 23
    TFT Data In (MOSI) 34 19
    D/C 36 18
    Reset 10 16
    Chip Select 38 24
  2. See list of supported devices for module:

    sudo modprobe fbtft_device name=list; dmesg | tail -50
    

    We want adafruit28

  3. Edit /etc/modprobe.d/fbtft.conf and add the following:

    options fbtft_device name=adafruit28 cs=0 gpios=reset:23,dc:24 rotate=0
    
  4. Edit /etc/modules-load.d/fbtft.conf and add:

    spi-bcm2835
    fbtft_device
    
  5. Add the following the end of the line in /boot/cmdline.txt (right after rootwait)

    fbcon=map:10 fbcon=font:VGA8x8 logo.nologo
    
  6. For a better console font: sudo dpkg-reconfigure console-setup and select: UTF 8 > Guess optimal... > Terminus > 6x12

  7. Turn on console output: sudo con2fbmap 1 1

  8. Restart

Sending text to the screen via SSH

To output to the screen, modify permissions on /dev/tty1:

sudo chmod 666 /dev/tty1

Send text to the screen via ssh:

echo -ne "asdf" > /dev/tty1

Wake the screen up if it's gone to sleep:

echo -ne "\033[9;0]" > /dev/tty1

Clear the screen:

echo -ne "\033[2J" > /dev/tty1

Disable the blinking cursor:

echo -ne '\033[?17;0;0c' > /dev/tty1

Disable screen blanking/sleep

Edit /boot/cmdline.txt and add this to the end of the line:

consoleblank=0

Startup

I set things up to login to a specific user on startup and run the project app.

  1. Automatically login to the app user, edit /etc/systemd/system/getty.target.wants/[email protected] and add this line under [Service]:

    ExecStart=-/sbin/agetty --autologin app --noclear %I $TERM
    
  2. Enable the service: systemctl enable getty@tty1

  3. Run a specific program, add this to end of app's .bashrc file:

    # clear the screen
    echo -ne "\033[2J"
    # start the app
    cd /home/app/charloop && node app.js
    

Custom boot splash screen

  1. Install fbi: apt-get install fbi

  2. Create /etc/systemd/system/splashscreen.service with:

    [Unit]
    Description=Splash screen
    DefaultDependencies=no
    After=local-fs.target
    
    [Service]
    ExecStart=/usr/bin/fbi --noverbose -a /opt/splash.png
    StandardInput=tty
    StandardOutput=tty
    
    [Install]
    WantedBy=sysinit.target
    
  3. Copy your splash image to /opt/splash.png. Make it 240x320 to exactly fit the screen.

  4. Enable the service: systemctl enable splashscreen

Remove boot/shutdown text

  1. This might remove some: edit /boot/cmdline.txt and add:

    quiet loglevel=3
    
  2. This will clear the screen after everything else is run, so at least you see less text after the splash screen goes away. Add this to the end of etc/rc.local:

    # clears the screen
    echo -ne "\033[2J"
    
  3. Disable the motd. Edit /etc/pam.d/login, comment out these lines:

    #session    optional   pam_lastlog.so
    #session    optional   pam_motd.so motd=/run/motd.dynamic
    #session    optional   pam_motd.so noupdate
    #session    optional   pam_mail.so standard
    
  4. Remove some extra login messages and clear the screen on the login prompt:

    sudo su -
    clear > /etc/issue
    

Disable Bluetooth

Bluetooth was causing a pin to stay high, that I was hoping to use to determine when the Raspi shut down. Also, bluetooth isn't used and will just waste power.

  1. Add this to /boot/config.txt:
# Disable Bluetooth
dtoverlay=pi3-disable-bt
  1. Disable related services:
sudo systemctl disable bluetooth.service
  1. Restart

Soft Power

I want to use a "soft power" switch to turn the Raspi on/off (because it's a computer, yo). I don't want it to consume any power while it's off. I came up with an idea that I think will work. I'll include a schematic and a state machien diagram hopefully. It uses an ATTiny85. The code is in the soft-power folder.

Compile/Install

NOTE: The makefile uses avr-gcc and avrdude to compile and upload. It also assumes you're using a usbtiny programmer, like the Sparkfun Pocket AVR Programmer.

  1. Connect your programmer

  2. Compile and upload

    $ cd soft-power
    $ make upload
    

Parts List

References

Raspberry Pi

Node

TFT Display

Startup

WAV Files

charloop's People

Contributors

cullylarson avatar

Watchers

 avatar

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.