Jannaveve

Tweeting Patch

The second iteration of this project is the Bluetooth tweeting version. It would not be 2019 if everything were not part of the internet of things, so I devised a plan to connect P@tch to social media. The Bluetooth module connects to an app on a users phone which then sends the data to a data feed on an open source platform. It then triggers another online application I created using IFTTT to transmit data from the users data feed to their twitter account.

Supply List

1k Ohm resistor

Tactile Button Switch

Adafruit NeoPixel

Adafruit Flora

Adafruit Flora Wearable Bluefruit LE 

Circuit Diagram

circuitdiagram-01

Code Example

#include <Arduino.h>
#include <SPI.h>
#if not defined (_VARIANT_ARDUINO_DUE_X_) && not defined (_VARIANT_ARDUINO_ZERO_)
#include <SoftwareSerial.h>
#endif

#include <Wire.h>
#include “Adafruit_BLE.h”
#include “Adafruit_BluefruitLE_SPI.h”
#include “Adafruit_BluefruitLE_UART.h”
#include “BluefruitConfig.h”

#include <Adafruit_NeoPixel.h>

#define BUTTON_PIN 6 // Digital IO pin connected to the button. This will be
// driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily. On a high -> low
// transition the button press logic will execute.

#define PIXEL_PIN 10 // Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 1

#define FACTORYRESET_ENABLE 1
#define MINIMUM_FIRMWARE_VERSION “0.6.6”
#define MODE_LED_BEHAVIOUR “MODE”
#define BLUEFRUIT_HWSERIAL_NAME Serial1

/* …or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);
// A small helper
void error(const __FlashStringHelper*err) {
Serial.println(err);
while (1);
}

// Parameter 1 = number of pixels in strip, neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

bool oldState = HIGH;
int showType = 0;

void setup() {

while (!Serial); // required for Flora & Micro
delay(500);

Serial.begin(115200);

Serial.println(“Button Test”); Serial.println(“”);

pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to ‘off’

/* We’re ready to go! */
Serial.println(“”);

Serial.println(F(“Adafruit Bluefruit Command <-> Data Mode Example”));
Serial.println(F(“————————————————“));

/* Initialise the module */
Serial.print(F(“Initialising the Bluefruit LE module: “));

if ( !ble.begin(VERBOSE_MODE) )
{
error(F(“Couldn’t find Bluefruit, make sure it’s in CoMmanD mode & check wiring?”));
}
Serial.println( F(“OK!”) );

if ( FACTORYRESET_ENABLE )
{
/* Perform a factory reset to make sure everything is in a known state */
Serial.println(F(“Performing a factory reset: “));
if ( ! ble.factoryReset() ){
error(F(“Couldn’t factory reset”));
}
}

/* Disable command echo from Bluefruit */
ble.echo(false);

Serial.println(“Requesting Bluefruit info:”);
/* Print Bluefruit information */
ble.info();

Serial.println(F(“Please use Adafruit Bluefruit LE app to connect in UART mode”));
Serial.println(F(“Then Enter characters to send to Bluefruit”));
Serial.println();

ble.verbose(false); // debug info is a little annoying after this point!

/* Wait for connection */
while (! ble.isConnected()) {
delay(500);
}

Serial.println(F(“******************************”));

// LED Activity command is only supported from 0.6.6
if ( ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION) )
{
// Change Mode LED Activity
Serial.println(F(“Change LED activity to ” MODE_LED_BEHAVIOUR));
ble.sendCommandCheckOK(“AT+HWModeLED=” MODE_LED_BEHAVIOUR);
}

// Set module to DATA mode
Serial.println( F(“Switching to DATA mode!”) );
ble.setMode(BLUEFRUIT_MODE_DATA);

Serial.println(F(“******************************”));
}

void loop() {
// Get current button state.
bool newState = digitalRead(BUTTON_PIN);

// Check if state changed from high to low (button press).
if (newState == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState = digitalRead(BUTTON_PIN);
if (newState == LOW) {
showType++;
if (showType > 2)
showType=0;
startShow(showType);
}
}

// Set the last button state to the old state.
oldState = newState;
}

void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(0, 0, 0), 50); // Black/off
Serial.println(“off”);
break;
case 1: colorWipe(strip.Color(255, 0, 0), 50); // Red
ble.println(“red”);
Serial.println(“red”);
break;
case 2: colorWipe(strip.Color(0, 255, 0), 50); // Green
ble.println(“Green”);
Serial.println(“Green”);
break;
}
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}

Bluetooth Config Tab

// COMMON SETTINGS
// ———————————————————————————————-
// These settings are used in both SW UART, HW UART and SPI mode
// ———————————————————————————————-
#define BUFSIZE 128 // Size of the read buffer for incoming data
#define VERBOSE_MODE true // If set to ‘true’ enables debug output
// SOFTWARE UART SETTINGS
// ———————————————————————————————-
// The following macros declare the pins that will be used for ‘SW’ serial.
// You should use this option if you are connecting the UART Friend to an UNO
// ———————————————————————————————-
#define BLUEFRUIT_SWUART_RXD_PIN 9 // Required for software serial!
#define BLUEFRUIT_SWUART_TXD_PIN 10 // Required for software serial!
#define BLUEFRUIT_UART_CTS_PIN -1 // Required for software serial!
#define BLUEFRUIT_UART_RTS_PIN -1 // Optional, set to -1 if unused
// HARDWARE UART SETTINGS
// ———————————————————————————————-
// The following macros declare the HW serial port you are using. Uncomment
// this line if you are connecting the BLE to Leonardo/Micro or Flora
// ———————————————————————————————-
//#ifdef Serial1 // this makes it not complain on compilation if there’s no Serial1
#define BLUEFRUIT_HWSERIAL_NAME Serial1
//#endif
// SHARED UART SETTINGS
// ———————————————————————————————-
// The following sets the optional Mode pin, its recommended but not required
// ———————————————————————————————-
#define BLUEFRUIT_UART_MODE_PIN -1 // Set to -1 if unused
// SHARED SPI SETTINGS
// ———————————————————————————————-
// The following macros declare the pins to use for HW and SW SPI communication.
// SCK, MISO and MOSI should be connected to the HW SPI pins on the Uno when
// using HW SPI. This should be used with nRF51822 based Bluefruit LE modules
// that use SPI (Bluefruit LE SPI Friend).
// ———————————————————————————————-
#define BLUEFRUIT_SPI_CS 8
#define BLUEFRUIT_SPI_IRQ 7
#define BLUEFRUIT_SPI_RST 6 // Optional but recommended, set to -1 if unused

// SOFTWARE SPI SETTINGS
// ———————————————————————————————-
// The following macros declare the pins to use for SW SPI communication.
// This should be used with nRF51822 based Bluefruit LE modules that use SPI
// (Bluefruit LE SPI Friend).
// ———————————————————————————————-
#define BLUEFRUIT_SPI_SCK 13
#define BLUEFRUIT_SPI_MISO 12
#define BLUEFRUIT_SPI_MOSI 11

%d bloggers like this: