Skip to content

Instantly share code, notes, and snippets.

@dvanduzer
Last active February 22, 2016 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvanduzer/4b54e6885ad0ffdaebe8 to your computer and use it in GitHub Desktop.
Save dvanduzer/4b54e6885ad0ffdaebe8 to your computer and use it in GitHub Desktop.
sample sketch configure for Pinoccio pins
/**************************************************************************\
* Pinoccio Library *
* https://github.com/Pinoccio/library-pinoccio *
* Copyright (c) 2014, Pinoccio Inc. All rights reserved. *
* ------------------------------------------------------------------------ *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the MIT License as described in license.txt. *
\**************************************************************************/
#include <inttypes.h>
#include <ctype.h>
#include <SPI.h>
#include <Wire.h>
#include <Scout.h>
#include <GS.h>
#include <bitlash.h>
#include <lwm.h>
#include <js0n.h>
#include <FLASH.h>
#include <EPD.h>
#include <S5813A.h>
#include "version.h"
// Change this for different display size
// supported sizes: 144 200 270
#define SCREEN_SIZE 144
// select two images from: text_image text-hello cat aphrodite venus saturn
#define IMAGE_1 text_image
#define IMAGE_2 cat
// set up images from screen size2
#if (SCREEN_SIZE == 144)
#define EPD_SIZE EPD_1_44
#define FILE_SUFFIX _1_44.xbm
#define NAME_SUFFIX _1_44_bits
#elif (SCREEN_SIZE == 200)
#define EPD_SIZE EPD_2_0
#define FILE_SUFFIX _2_0.xbm
#define NAME_SUFFIX _2_0_bits
#elif (SCREEN_SIZE == 270)
#define EPD_SIZE EPD_2_7
#define FILE_SUFFIX _2_7.xbm
#define NAME_SUFFIX _2_7_bits
#else
#error "Unknown EPB size: Change the #define SCREEN_SIZE to a supported value"
#endif
// current version number
#define DEMO_VERSION "2"
// pre-processor convert to string
#define MAKE_STRING1(X) #X
#define MAKE_STRING(X) MAKE_STRING1(X)
// other pre-processor magic
// tiken joining and computing the string for #include
#define ID(X) X
#define MAKE_NAME1(X,Y) ID(X##Y)
#define MAKE_NAME(X,Y) MAKE_NAME1(X,Y)
#define MAKE_JOIN(X,Y) MAKE_STRING(MAKE_NAME(X,Y))
// calculate the include name and variable names
#define IMAGE_1_FILE MAKE_JOIN(IMAGE_1,FILE_SUFFIX)
#define IMAGE_1_BITS MAKE_NAME(IMAGE_1,NAME_SUFFIX)
#define IMAGE_2_FILE MAKE_JOIN(IMAGE_2,FILE_SUFFIX)
#define IMAGE_2_BITS MAKE_NAME(IMAGE_2,NAME_SUFFIX)
// Add Images library to compiler path
#include <Images.h> // this is just an empty file
// images
PROGMEM const
#define unsigned
#define char uint8_t
#include IMAGE_1_FILE
#undef char
#undef unsigned
PROGMEM const
#define unsigned
#define char uint8_t
#include IMAGE_2_FILE
#undef char
#undef unsigned
const int Pin_TEMPERATURE = A0;
const int Pin_PANEL_ON = D2;
const int Pin_BORDER = D3;
const int Pin_DISCHARGE = D4;
const int Pin_PWM = D5;
const int Pin_RESET = D6;
const int Pin_BUSY = D7;
const int Pin_EPD_CS = D8;
const int Pin_FLASH_CS = A7;
// what is this for?
// http://repaper.org/doc/extension_board.html#pin-assignment
// const int Pin_SW2 = 12;
const int Pin_RED_LED = LED_BLUE;
// LED anode through resistor to I/O pin
// LED cathode to Ground
#define LED_ON HIGH
#define LED_OFF LOW
// pre-processor convert to string
#define MAKE_STRING1(X) #X
#define MAKE_STRING(X) MAKE_STRING1(X)
// function prototypes
static void flash_info(void);
static void flash_read(void *buffer, uint32_t address, uint16_t length);
static uint16_t xbm_count;
static bool xbm_parser(uint8_t *b);
static uint8_t Serial_getc();
static uint16_t Serial_gethex(bool echo);
static void Serial_puthex(uint32_t n, int bits);
static void Serial_puthex_byte(uint8_t n);
static void Serial_puthex_word(uint16_t n);
static void Serial_puthex_double(uint32_t n);
static void Serial_hex_dump(uint32_t address, const void *buffer, uint16_t length);
// define the E-Ink display
EPD_Class EPD(EPD_SIZE, Pin_PANEL_ON, Pin_BORDER, Pin_DISCHARGE, Pin_PWM, Pin_RESET, Pin_BUSY, Pin_EPD_CS);
void setup() {
Scout.setup(SKETCH_NAME, SKETCH_REVISION, SKETCH_BUILD);
// Add custom setup code here
Scout.setMode(Pin_RED_LED, OUTPUT);
// Scout.setMode(Pin_SW2, INPUT);
Serial.println(Scout.getTemperatureC());
if(Scout.setMode(Pin_TEMPERATURE, INPUT) && Scout.isAnalogPin(Pin_TEMPERATURE)) {
Serial.println("TEMP pin set OK");
}
if(Scout.setMode(Pin_PWM, OUTPUT) && Scout.isPWMPin(Pin_PWM)) {
Serial.println("PWM pin set OK");
}
if(Scout.setMode(Pin_BUSY, INPUT) && Scout.isDigitalPin(Pin_BUSY)) {
Serial.println("BUSY pin set OK");
}
if(Scout.setMode(Pin_RESET, OUTPUT) && Scout.isDigitalPin(Pin_RESET)) {
Serial.println("RESET pin set OK");
}
if(Scout.setMode(Pin_PANEL_ON, OUTPUT) && Scout.isDigitalPin(Pin_PANEL_ON)) {
Serial.println("PANEL_ON pin set OK");
}
if(Scout.setMode(Pin_DISCHARGE, OUTPUT) && Scout.isDigitalPin(Pin_DISCHARGE)) {
Serial.println("DISCHARGE pin set OK");
}
if(Scout.setMode(Pin_BORDER, OUTPUT) && Scout.isDigitalPin(Pin_BORDER)) {
Serial.println("BORDER pin set OK");
}
//if(Scout.setMode(Pin_EPD_CS, OUTPUT) && Scout.isDigitalPin(Pin_EPD_CS)) {
if(Scout.setMode(Pin_EPD_CS, OUTPUT)) {
Serial.println("EPD_CS pin set OK");
} else {
Serial.println("EPD_CS pin NOT SET");
}
//if(Scout.setMode(Pin_FLASH_CS, OUTPUT) && Scout.isDigitalPin(Pin_FLASH_CS)) {
if(Scout.setMode(Pin_FLASH_CS, OUTPUT)) {
Serial.println("FLASH_CS pin set OK");
} else {
Serial.println("FLASH_CS pin NOT SET");
}
FLASH.begin(Pin_FLASH_CS);
if (FLASH.available()) {
Serial.println("FLASH chip detected OK");
} else {
uint8_t maufacturer;
uint16_t device;
FLASH.info(&maufacturer, &device);
Serial.print("unsupported FLASH chip: MFG: 0x");
Serial.print(maufacturer, HEX);
Serial.print(" device: 0x");
Serial.print(device, HEX);
Serial.println();
}
// configure temperature sensor
S5813A.begin(Pin_TEMPERATURE);
}
static int state = 0;
void loop() {
//Scout.loop();
//int temperature = S5813A.read();
int temperature = Scout.getTemperatureC();
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" Celcius");
EPD.begin(); // power up the EPD panel
EPD.setFactor(temperature); // adjust for current temperature
int delay_counts = 50;
switch(state) {
default:
case 0: // clear the screen
EPD.clear();
state = 1;
delay_counts = 5; // reduce delay so first image come up quickly
break;
case 1: // clear -> text
EPD.image(IMAGE_1_BITS);
++state;
break;
case 2: // text -> picture
EPD.image(IMAGE_1_BITS, IMAGE_2_BITS);
++state;
break;
case 3: // picture -> text
EPD.image(IMAGE_2_BITS, IMAGE_1_BITS);
state = 2; // backe to picture nex time
break;
}
EPD.end(); // power down the EPD panel
// flash LED for 5 seconds
for (int x = 0; x < delay_counts; ++x) {
digitalWrite(Pin_RED_LED, LED_ON);
delay(50);
digitalWrite(Pin_RED_LED, LED_OFF);
delay(50);
}
}
static void flash_info(void) {
uint8_t maufacturer;
uint16_t device;
if (FLASH.available()) {
Serial.println("FLASH chip detected OK");
} else {
Serial.println("unsupported FLASH chip");
}
FLASH.info(&maufacturer, &device);
Serial.print("FLASH: manufacturer = ");
Serial_puthex_byte(maufacturer);
Serial.print(" device = ");
Serial_puthex_word(device);
Serial.println();
}
static void flash_read(void *buffer, uint32_t address, uint16_t length) {
FLASH.read(buffer, address, length);
}
static bool xbm_parser(uint8_t *b) {
for (;;) {
uint8_t c = Serial_getc();
if ('0' == c && 'x' == Serial_getc()) {
*b = Serial_gethex(false);
++xbm_count;
if (0 == (xbm_count & 0x07)) {
digitalWrite(Pin_RED_LED, !digitalRead(Pin_RED_LED));
}
return true;
} else if (';' == c) {
break;
}
}
digitalWrite(Pin_RED_LED, LED_OFF);
return false;
}
// miscellaneous serial interface routines
static uint8_t Serial_getc() {
while (0 == Serial.available()) {
}
return Serial.read();
}
static uint16_t Serial_gethex(bool echo) {
uint16_t acc = 0;
for (;;) {
uint8_t c = Serial_getc();
if (c >= '0' && c <= '9') {
c -= '0';
} else if (c >= 'a' && c <= 'f') {
c -= 'a' - 10;
} else if (c >= 'A' && c <= 'F') {
c -= 'A' - 10;
} else {
return acc;
}
if (echo) {
Serial_puthex(c, 4);
}
acc <<= 4;
acc += c;
}
}
static void Serial_puthex(uint32_t n, int bits) {
for (int i = bits - 4; i >= 0; i -= 4) {
char nibble = ((n >> i) & 0x0f) + '0';
if (nibble > '9') {
nibble += 'a' - '9' - 1;
}
Serial.print(nibble);
}
}
static void Serial_puthex_byte(uint8_t n) {
Serial_puthex(n, 8);
}
static void Serial_puthex_word(uint16_t n) {
Serial_puthex(n, 16);
}
static void Serial_puthex_double(uint32_t n) {
Serial_puthex(n, 32);
}
static void Serial_hex_dump(uint32_t address, const void *buffer, uint16_t length) {
const uint8_t *p = (const uint8_t *)buffer;
while (0 != length) {
Serial_puthex_double(address);
Serial.print(": ");
for (int i = 0; i < 16; ++i, ++address) {
Serial_puthex_byte(*p++);
Serial.print(' ');
if (7 == i) {
Serial.print(' ');
}
if (--length == 0) {
break;
}
}
Serial.println();
}
}
// -*- mode: c++ -*-
// Copyright 2013 Pervasive Displays, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language
// governing permissions and limitations under the License.
// Simple demo to toggle EPD between two images.
// Operation from reset:
// * display version
// * display compiled-in display setting
// * display FLASH detected or not
// * display temperature (displayed before every image is changed)
// * clear screen
// * delay 5 seconds (flash LED)
// * display text image
// * delay 5 seconds (flash LED)
// * display picture
// * delay 5 seconds (flash LED)
// * back to text display
#include <inttypes.h>
#include <ctype.h>
// required libraries
#include <SPI.h>
#include <FLASH.h>
#include <EPD.h>
#include <S5813A.h>
// Change this for different display size
// supported sizes: 144 200 270
#define SCREEN_SIZE 144
// select two images from: text_image text-hello cat aphrodite venus saturn
#define IMAGE_1 text_image
#define IMAGE_2 cat
// set up images from screen size2
#if (SCREEN_SIZE == 144)
#define EPD_SIZE EPD_1_44
#define FILE_SUFFIX _1_44.xbm
#define NAME_SUFFIX _1_44_bits
#elif (SCREEN_SIZE == 200)
#define EPD_SIZE EPD_2_0
#define FILE_SUFFIX _2_0.xbm
#define NAME_SUFFIX _2_0_bits
#elif (SCREEN_SIZE == 270)
#define EPD_SIZE EPD_2_7
#define FILE_SUFFIX _2_7.xbm
#define NAME_SUFFIX _2_7_bits
#else
#error "Unknown EPB size: Change the #define SCREEN_SIZE to a supported value"
#endif
// Error message for MSP430
#if (SCREEN_SIZE == 270) && defined(__MSP430_CPU__)
#error MSP430: not enough memory
#endif
// no futher changed below this point
// current version number
#define DEMO_VERSION "2"
// pre-processor convert to string
#define MAKE_STRING1(X) #X
#define MAKE_STRING(X) MAKE_STRING1(X)
// other pre-processor magic
// tiken joining and computing the string for #include
#define ID(X) X
#define MAKE_NAME1(X,Y) ID(X##Y)
#define MAKE_NAME(X,Y) MAKE_NAME1(X,Y)
#define MAKE_JOIN(X,Y) MAKE_STRING(MAKE_NAME(X,Y))
// calculate the include name and variable names
#define IMAGE_1_FILE MAKE_JOIN(IMAGE_1,FILE_SUFFIX)
#define IMAGE_1_BITS MAKE_NAME(IMAGE_1,NAME_SUFFIX)
#define IMAGE_2_FILE MAKE_JOIN(IMAGE_2,FILE_SUFFIX)
#define IMAGE_2_BITS MAKE_NAME(IMAGE_2,NAME_SUFFIX)
// Add Images library to compiler path
#include <Images.h> // this is just an empty file
// images
PROGMEM const
#define unsigned
#define char uint8_t
#include IMAGE_1_FILE
#undef char
#undef unsigned
PROGMEM const
#define unsigned
#define char uint8_t
#include IMAGE_2_FILE
#undef char
#undef unsigned
// Pinoccio customized
#define RX0 0
#define TX0 1
#define D2 2
#define D3 3
#define D4 4
#define D5 5
#define D6 6
#define D7 7
#define D8 8
#define SS 9
#define MOSI 10
#define MISO 11
#define SCK 12
#define RX1 13
#define TX1 14
#define SCL 15
#define SDA 16
#define VCC_ENABLE 17
#define BATT_ALERT 18
#define BACKPACK_BUS 19
#define CHG_STATUS 20
#define LED_BLUE 21
#define LED_RED 22
#define LED_GREEN 23
#define LED_BUILTIN 23
#define LED 23
#define A0 24
#define A1 25
#define A2 26
#define A3 27
#define A4 28
#define A5 29
#define A6 30
#define A7 31
const int Pin_TEMPERATURE = A0;
const int Pin_PANEL_ON = D2;
const int Pin_BORDER = D3;
const int Pin_DISCHARGE = D4;
const int Pin_PWM = D5;
const int Pin_RESET = D6;
const int Pin_BUSY = D7;
const int Pin_EPD_CS = SDA;
const int Pin_FLASH_CS = SCL;
// what is this for?
// http://repaper.org/doc/extension_board.html#pin-assignment
// const int Pin_SW2 = 12;
const int Pin_RED_LED = LED_BLUE;
// LED anode through resistor to I/O pin
// LED cathode to Ground
#define LED_ON HIGH
#define LED_OFF LOW
// define the E-Ink display
EPD_Class EPD(EPD_SIZE, Pin_PANEL_ON, Pin_BORDER, Pin_DISCHARGE, Pin_PWM, Pin_RESET, Pin_BUSY, Pin_EPD_CS);
// I/O setup
void setup() {
pinMode(Pin_RED_LED, OUTPUT);
// pinMode(Pin_SW2, INPUT);
pinMode(Pin_TEMPERATURE, INPUT);
pinMode(Pin_PWM, OUTPUT);
pinMode(Pin_BUSY, INPUT);
pinMode(Pin_RESET, OUTPUT);
pinMode(Pin_PANEL_ON, OUTPUT);
pinMode(Pin_DISCHARGE, OUTPUT);
pinMode(Pin_BORDER, OUTPUT);
pinMode(Pin_EPD_CS, OUTPUT);
pinMode(Pin_FLASH_CS, OUTPUT);
digitalWrite(Pin_RED_LED, LOW);
digitalWrite(Pin_PWM, LOW);
digitalWrite(Pin_RESET, LOW);
digitalWrite(Pin_PANEL_ON, LOW);
digitalWrite(Pin_DISCHARGE, LOW);
digitalWrite(Pin_BORDER, LOW);
digitalWrite(Pin_EPD_CS, LOW);
digitalWrite(Pin_FLASH_CS, HIGH);
Serial.begin(9600);
#if !defined(__MSP430_CPU__)
// wait for USB CDC serial port to connect. Arduino Leonardo only
while (!Serial) {
}
#endif
Serial.println();
Serial.println();
Serial.println("Demo version: " DEMO_VERSION);
Serial.println("Display: " MAKE_STRING(EPD_SIZE));
Serial.println();
FLASH.begin(Pin_FLASH_CS);
if (FLASH.available()) {
Serial.println("FLASH chip detected OK");
} else {
uint8_t maufacturer;
uint16_t device;
FLASH.info(&maufacturer, &device);
Serial.print("unsupported FLASH chip: MFG: 0x");
Serial.print(maufacturer, HEX);
Serial.print(" device: 0x");
Serial.print(device, HEX);
Serial.println();
}
// configure temperature sensor
S5813A.begin(Pin_TEMPERATURE);
}
static int state = 0;
// main loop
void loop() {
int temperature = S5813A.read();
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" Celcius");
EPD.begin(); // power up the EPD panel
EPD.setFactor(temperature); // adjust for current temperature
int delay_counts = 50;
switch(state) {
default:
case 0: // clear the screen
EPD.clear();
state = 1;
delay_counts = 5; // reduce delay so first image come up quickly
break;
case 1: // clear -> text
EPD.image(IMAGE_1_BITS);
++state;
break;
case 2: // text -> picture
EPD.image(IMAGE_1_BITS, IMAGE_2_BITS);
++state;
break;
case 3: // picture -> text
EPD.image(IMAGE_2_BITS, IMAGE_1_BITS);
state = 2; // backe to picture nex time
break;
}
EPD.end(); // power down the EPD panel
// flash LED for 5 seconds
for (int x = 0; x < delay_counts; ++x) {
digitalWrite(Pin_RED_LED, LED_ON);
delay(50);
digitalWrite(Pin_RED_LED, LED_OFF);
delay(50);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment