Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Carol ChesneyVann Chesney
Published © GPL3+

Poetry Heart in Motion

Magic conversation heart (like Sally Brown's from Peanuts) contains entire sonnet - just flip it over and over.

IntermediateFull instructions provided3 hours678

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
Adafruit SSD1306 oled
or other 0.96'' 128X64 Pixel OLED LCD with selectable I2C address
×2
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
Or similar
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

Heart lid

Heart Base

Schematics

Connection Diagram

Connect both displays to I2C bus. Make sure each has a different address. You may need to resolder a jumper on the display.

Yellow SCL -> SCL
Orange SDA -> SDA
Blue RST -> A0

Code

Love Poetry in motion

Arduino
You may use this code as is or swap in your own poem.
Hints, use a \n to force line breaks
If your poem has special characters, remember to use the proper escape sequence.
For example a single quote is \'
/*This code written by Vann and Carol Chesney
   using the documented Adafruit libraries and examples

   Project inspired by Peanuts Valentine special.
   Sally Brown reads her conversation heart out loud.
   It contains the entire Sonnet 43 by Elizabeth Barrett Browning
   She has to flip the heart over and anver again to read it all.

   This code uses Adafruit's CPX to print out a few lines at a time
   to two different OLED displays on I2C bus
   The built in accelerometer detects when the unit is flipped

   Please see the additional documentation for all the Adafruit references
*/
#include <Adafruit_CircuitPlayground.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

int textSize = 1 ;
String Poem[] = { "\n\n"
                  "How do I love thee?\n\n"
                  "Let me count\n the ways.\n\n        (over -> )",
                  "I love thee to the\n"
                  " depth and breadth\n"
                  "and height My soul\n"
                  " can reach, when\n"
                  "feeling out of sight\n\n        (over -> )",
                  "For the ends of being\n"
                  " and ideal grace.\n"
                  "I love thee to the \n"
                  " level of every\n"
                  " day\'s Most quiet\n"
                  " need, by sun and \n"
                  " candle-light.\n             ->",
                  "I love thee freely,\n"
                  "as men strive for \n"
                  "right.\n\n"
                  "I love thee purely,\n"
                  "as they turn from\n"
                  "praise.\n             ->",
                  "I love thee with the\n"
                  "passion put to use\n"
                  "In my old griefs,\n"
                  " and with my \n"
                  "childhood\'s faith.\n\n        ->",
                  "I love thee with a\n"
                  "love I seemed to lose\n"
                  " With my lost saints.\n"
                  "I love thee with the\n"
                  " breath, Smiles,\n"
                  " tears, of all\n"
                  " my life;\n     ->",
                  "\n\n\n"
                  "and, if God choose,\n"
                  " I shall but love\n"
                  " thee better after\n"
                  " death.",
                  "\n\n -> -> ->-> -> ->\n\nTurn over to reset\n\n-> -> ->-> -> ->"
                };
int poemLines = sizeof(Poem) / sizeof(Poem[0]);
float newZ, oldZ;
/*
  Begin Adafruit Graphics example

*/
/**************************************************************************
  This is an example for our Monochrome OLEDs based on SSD1306 drivers

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/category/63_98

  This example is for a 128x32 pixel display using I2C to communicate
  3 pins are required to interface (two I2C and one reset).

  Adafruit invests time and resources providing this open
  source code, please support Adafruit and open-source
  hardware by purchasing products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries,
  with contributions from the open source community.
  BSD license, check license.txt for more information
  All text above, and the splash screen below must be
  included in any redistribution.
 **************************************************************************/
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     6 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 

void setup() {
  Serial.begin(9600);
  CircuitPlayground.begin();
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for first display
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display2.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for second display
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  display2.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();
  display.display();
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);

  // Clear the buffer
  display2.clearDisplay();
  display2.display();
  display2.setTextSize(3);
  display2.setTextColor(WHITE);
  display2.setCursor(0, 0);

  Serial.print("Pick me up!\n");
  display.println(" Pick\nme up!");
  display.display();
  display2.println(" Pick\nme up!");
  display2.display();
  while (CircuitPlayground.motionZ() > 7.5) {
    Serial.print("  Z: ");
    Serial.println(CircuitPlayground.motionZ());
    delay(100);
  }
  oldZ = CircuitPlayground.motionZ();
  Serial.print("  Lines of poetry: ");
  Serial.println(poemLines);
  Serial.print("  Z: ");
  Serial.println(oldZ);
  display.setTextSize(textSize);
  display2.setTextSize(textSize);
}

void loop() {

  for ( int poemLine = 0; poemLine < poemLines; poemLine++) {
    newZ = CircuitPlayground.motionZ();
    delay(200);       // Needed to "de-bounce"

    Serial.println(Poem[poemLine]);
    display.clearDisplay();
    display.setCursor(0, 0);
    display.println(Poem[poemLine]);
    display.display();
    display2.clearDisplay();
    display2.setCursor(0, 0);
    display2.println(Poem[poemLine]);
    display2.display();
    while ( (newZ * oldZ) > 0)  {  // sign change
      newZ = CircuitPlayground.motionZ();
      delay(100);
    }
    oldZ = newZ;
  }

}

Credits

Carol Chesney

Carol Chesney

5 projects • 9 followers
Mechanical engineer and teacher
Vann Chesney

Vann Chesney

1 project • 0 followers
Thanks to Adafruit.

Comments