BlueFruit Project: Time Out!

Zip created at /tmp/arduino_build_587243/sketch_dec29a.ino.zip
Using library Bluefruit52Lib at version 0.7.5 in folder: /home/alaskalinuxuser/.arduino15/packages/adafruit/hardware/nrf52/0.7.5/libraries/Bluefruit52Lib
Using library nffs at version 1.0.0 in folder: /home/alaskalinuxuser/.arduino15/packages/adafruit/hardware/nrf52/0.7.5/libraries/nffs
Sketch uses 59352 bytes (35%) of program storage space. Maximum is 167936 bytes.
Global variables use 4852 bytes (9%) of dynamic memory, leaving 46220 bytes for local variables. Maximum is 51072 bytes.
nrfutil –verbose dfu serial -pkg /tmp/arduino_build_587243/sketch_dec29a.ino.zip -p /dev/ttyUSB0 -b 115200
Upgrading target on /dev/ttyUSB0 with DFU package /tmp/arduino_build_587243/sketch_dec29a.ino.zip. Flow control is disabled.
Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, application size: 59764
Sending DFU start packet
Sending DFU init packet
Sending firmware file
######################################################################################################################
Activating new firmware
#
DFU upgrade took 11.5461740494s
Device programmed.

Time out! Well, not really, but it sounds catchy! Timing is really important. And that is what I had to adjust with this commit. I had a 500 ms delay between program runs, which takes about 500 ms to run. So, each run of the program takes roughly 1 second, which is great for setting the timing of the program.

Here’s the interesting part: the relays that I am using are the latching relay featherwings. They only need the power applied to set or unset the relay for 10 ms, then they will hold their last position. This is great for power savings. In my program, I want to capitalize on this power savings by having the outputs off all the time, when they are not specifically latching the relays.

2923-00

To make that happen, at the beginning of the loop of my program, I added a few lines to set all of the output pins low (15, 16, 7, and 11). While this will cut down on the power the board puts out (saving electricity, but also saving wear and tare, as well as making the code cleaner, since the state of the pins will always be known), it may cause me a slight issue. I don’t want it to cut down on the actually needed signal for when the outputs should be high to latch or unlatch a relay.

Confused yet? Well, let me explain. Here is how the program looks functionally:

  1. Set all pins low.
  2. delay 500ms.
  3. run program, like setting some pins high.

As you can see, there is actually no time between running the program and setting all the pins back to low. I needed to ensure there was at least 10 ms after the program sets the pins high before the loop sets them all low again. I thought I could swap 1 and 2, making the delay first, but then there was no time between the setting of low pins and running the program. So I edited it like this:

  1. delay 250 ms.
  2. set all pins low.
  3. delay 250 ms.
  4. run program, like setting some pins high.

Now there will always be at least 250 ms (1/4 of a second) for the relays to latch before given a command to set the pins low. Conversely, after being set low, there is 250 ms before the program runs, allowing me to keep my (roughly) 1 second timing on the circuit. Probably a little overkill for what I need, but at least I know this will work, making the program more robust.

Linux – keep it simple.

BlueFruit Project: Analog and Digital Detection (Code Name ADD)

From the post last week, you can see that I ran into a snag with the BlueFruit Feather board. It should be able to read the analog inputs separate from one another, but for some odd reason, taking a 3.3vdc reading on A0 would return 3.3vdc on A0 and ~1.4vdc on A3, and vice versa when reading the other way. This is problematic, as I have A3 as the battery indicator and A0 as the brake light indicator.

The A3 battery indicator tells the circuit if the truck has started, due to the alternator kicking in and the voltage climbing over 14vdc. The A0 brake light indicator tells the circuit to shut down, because the user pushed the brakes. Can’t have both. I jumped onto the Adafruit Forums, and found some really helpful people there. However, I wasn’t able to find a reason for my dilemma.

Thus, I created a work around.

auto

I really need to know what voltage the battery is, however, I don’t need to know the voltage of the brake lights, just that the brake lights were pressed. So the battery voltage needs to be a fine tuned analog signal. The brake lights just need to answer the question of on or off, true or false, 1 or 0. Wait! 1 or 0 is binary, which is digital! What if I just had a digital representative for the brakes?

I’m currently re-working my schematics, but here is the gist of what I want to do with the brakes (only the relevant part of the circuit is shown):

brakelights

This will indicate high on the digital circuit, which usually needs above 3 vdc to read high. Test runs were good on my desk, so I’m going to press forward with it. You can check out the full commit on my GitHub, but here is the relevant portion:

// read the input on digital pin 30:
int sensorValue = digitalRead(30);
// print out the value you read:
if (sensorValue == 1) {
Serial.println(“Pin 30 HIGH “);
// Brakes have been pushed, shut down all autostart circuits.
// This will not affect actual engine run circuits, just the autostart
// ones. So the engine will stay running if the key is in and on.
digitalWrite(16, LOW);
digitalWrite(15, LOW);
digitalWrite(7, HIGH);
digitalWrite(11, HIGH);
crankTimer = -1;
startTimer = -1;
runTimer = -1;
startAttempts = -1;
Serial.println(” Kill All – Brakes pressed. “);
}

Just about done with the BlueFruit programming! Now I need to work on the app programming and iron out and construct the electronics portion.

Linux – keep it simple.

BlueFruit Project: Adding voltage detection….

Last week, when we looked at my code for the BlueFruit autostart, we came to realize that if it did not know that the truck was started, it would continue to crank, even if it was running. This is not good. Thinking about it, it seemed obvious that a simple solution would be voltage detection. While I still need to tailor the detected voltage, I think this will get the job done:

// read the input on analog pin 5:
int voltValue = analogRead(A5);
float voltVoltage = voltValue * (3.6 / 1023.0);
if (voltVoltage >= 0.8) {
// It has enough voltage, it is running.
Serial.print(“Pin A5: “);Serial.println(voltVoltage);
runBool = true;
} else {
// Not enough voltage, must not be running.
runBool = false;
}

if (runBool) {
// Since it is running, make sure we are not cranking!
crankTimer = -1;
startTimer = -1;
digitalWrite(15, LOW);
digitalWrite(11, HIGH);
}

While reading the voltage on A05, it will be able to discern if the engine is running or not, and state so as a boolean (true/false). I also added the option for it to retry to start after failing to do so. You can check out the whole project, and this commit on my GitHub.

It seems to flow through nicely, which is a plus.

autostart

One problem that I have, however, is that anything read on A5 also seems to read a smaller portion, but a portion none-the-less, on A0 (brake light detection). Anything read on A0 assumes that you are trying to push the brakes and turns off the autostart, which becomes problematic. Obviously, this is some sort of failure on my part to understand how or why this happens, and I’m going to need to look into it further.

Linux – keep it simple.

BlueFruit Project: Vehicle Autostart!

That’s right! My latest project is to turn my BlueFruit Feather into a functioning autostart for my old ’93 pickup. Looking back at my project prep posts, you will now hopefully understand what I was trying to test and learn from those experiments. The great thing about this project is that it is multi-faceted. There is cell phone app programming, BlueFruit (Arduino style) programming, and electronics. I’m really looking forward to making this work, and sharing that journey here!

First up is the BlueFruit program. I’ve been mulling this over for a while, and here is what I’ve got so far:

#include <bluefruit.h>

BLEUart bleuart;
BLEDis bledis; // DIS (Device Information Service) helper class instance
// Function prototypes for packetparser.cpp
uint8_t readPacket (BLEUart *ble_uart, uint16_t timeout);
float parsefloat (uint8_t *buffer);
void printHex (const uint8_t * data, const uint32_t numBytes);

// Packet buffer
extern uint8_t packetbuffer[];

int brightness = 0; // how bright the LED is
int fadeAmount = 10; // how many points to fade the LED by
int crankTimer = -1; // Time spent cranking engine.
int startTimer = -1; // Time spent between start and crank.
int runTimer = -1; // Time to run before auto shutoff.

void setup(void) {
Serial.begin(57600);
Serial.println(F(“——————————————-“));

Bluefruit.begin();
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
Bluefruit.setTxPower(4);
Bluefruit.setName(“Bluefruit_AlaskaLinuxUser”);

// Configure and start the BLE Uart service
bleuart.begin();

// Configure and Start the Device Information Service
Serial.println(“Configuring the Device Information Service”);
bledis.setManufacturer(“Adafruit Industries”);
bledis.setModel(“Bluefruit Feather52”);
bledis.begin();

// Set up and start advertising
startAdv();

pinMode(17, OUTPUT); //19 is blue LED, 17 is red LED.
pinMode(19, OUTPUT); //19 is blue LED, 17 is red LED.

pinMode(16, OUTPUT);
pinMode(15, OUTPUT);
pinMode(7, OUTPUT);
pinMode(11, OUTPUT);

digitalWrite(16, LOW);
digitalWrite(15, LOW);
digitalWrite(7, LOW);
digitalWrite(11, LOW);
analogWrite(19, 0);

 

}

void startAdv(void) {
// Advertising packet
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();

// Include the BLE UART (AKA ‘NUS’) 128-bit UUID
Bluefruit.Advertising.addService(bleuart);

// Secondary Scan Response packet (optional)
// Since there is no room for ‘Name’ in Advertising packet
Bluefruit.ScanResponse.addName();

Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don’t stop advertising after n seconds
}

void connect_callback(uint16_t conn_handle) {
(void) conn_handle;
Serial.println(“Connected”);
}

void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
(void) conn_handle;
(void) reason;

Serial.println();
Serial.println(“Disconnected”);
}

void loop(void) {

analogWrite(17, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 50) {
fadeAmount = -fadeAmount;
}
// wait for 500 milliseconds to see the dimming effect
delay(500);
// To print the brightness // Serial.println(brightness);

// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 – 1023) to a voltage (0 – 3.6V):
float voltage = sensorValue * (3.6 / 1023.0);
// print out the value you read:
if (voltage >= 0.8) {
Serial.print(“Pin A01: “);Serial.println(voltage);
// Brakes have been pushed, shut down all autostart circuits.
// This will not affect actual engine run circuits, just the autostart
// ones. So the engine will stay running if the key is in and on.
digitalWrite(16, LOW);
digitalWrite(15, LOW);
digitalWrite(7, HIGH);
digitalWrite(11, HIGH);
crankTimer = -1;
startTimer = -1;
runTimer = -1;
Serial.println(” Kill All – Brakes pressed. “);
}

if (runTimer == 0) {
// Turn everything off from the runTimer.
digitalWrite(16, LOW);
digitalWrite(15, LOW);
digitalWrite(7, HIGH);
digitalWrite(11, HIGH);
crankTimer = -1;
startTimer = -1;
runTimer = -1;
Serial.println(” Kill All – runTimer elapsed. “);
} else if (runTimer > 0) {
runTimer = runTimer -1;
Serial.print (” runTimer “); Serial.println(runTimer);
}

if (startTimer == 0) {
digitalWrite(15, HIGH);
crankTimer = 3;
startTimer = -1;
Serial.println (” crankTimer ON “);
} else if (startTimer > 0) {
startTimer = startTimer -1;
Serial.print (” startTimer “); Serial.println(startTimer);
}

if (crankTimer == 0) {
digitalWrite(15, LOW);
crankTimer = -1;
startTimer = -1;
runTimer = 600; // 600 seconds = 10 minutes of run time before shutdown.
Serial.println (” crankTimer OFF, runTimer started. “);
} else if (crankTimer > 0) {
crankTimer = crankTimer -1;
Serial.print (” crankTimer “); Serial.println(crankTimer);
}

// Wait for new data to arrive
uint8_t len = readPacket(&bleuart, 500);
if (len == 0) return;

// Buttons
if (packetbuffer[1] == ‘B’) {
uint8_t buttnum = packetbuffer[2] – ‘0’;
boolean pressed = packetbuffer[3] – ‘0’;
Serial.print (“Button “); Serial.print(buttnum);
if (pressed) {
Serial.println(” pressed”);
//bluart.print(“pressed”);
analogWrite(19, 50);
} else {
Serial.println(” released”);
analogWrite(19, 0);
}
if (buttnum == 1) { // Turn on vehicle.
digitalWrite(16, HIGH);
startTimer = 5;
} else if (buttnum == 2) {
// Turn everything off from the button.
digitalWrite(16, LOW);
digitalWrite(15, LOW);
digitalWrite(7, HIGH);
digitalWrite(11, HIGH);
crankTimer = -1;
startTimer = -1;
runTimer = -1;
Serial.println(” Kill All – Button pressed. “);
}
}

}

There are three principle variables, crankTimer, startTimer, and runTimer. There are also 4 digital pins and 1 analog pin in use (the board has several more, but I only need these).

Essentially, every second, it will run this loop:

  • Listen for button presses.
  • If they pressed button 1, set up start timer to activate relay for accessories and fuel pump, and set count down timer for 5 seconds until we crank.
  • If the start timer is running, count down.
  • When the start timer reaches 0, turn on cranking relay power, and set crank timer for 3 seconds.
  • If the crank timer is running, count down (while continuing to crank).
  • When the crank timer reaches 0, turn off cranking power, and set the run timer for ten minutes.
  • If the run timer is running, count down.
  • When the run timer reaches 0, turn off relay for accessories and fuel pump.
  • If button 2 pressed at any time, turn off all relays. (Shutdown)
  • If brakes are pressed, turn off all relays. (Shutdown)

I’ve made an animated gif out of a video that I took while running the program.

autostart_test1

So far there are two main problems with my program:

  1. It doesn’t know if you have actually started the vehicle or not, so it will crank for 3 seconds regardless.
  2. Since it doesn’t know if the vehicle started or not, it will assume it did and not make multiple attempts.

However, I feel that if I dig a little deeper, I can find a way to use the tachometer wire and another analog pin to overcome this. Another option is voltage sensing. The truck battery is typically under 13 volts direct current. However, once started, the voltage jumps up to 14 or 14.5 VDC. While I would need to scale it down, as I am doing with the brake lights voltage, it is possible to read this voltage as an indicator of start and potentially continued run status.

Linux – keep it simple.

Project Prep: Communicating with the Bluefruit Feather via Bluetooth….

We’ve already connected to our Bluefruit feather with Bluetooth before, but when I wrote the sketches that I applied to it, it overwrote the code that allows it to turn on the Bluetooth function. So, today my goal was to get the Bluetooth working.

#include <bluefruit.h>

BLEUart bleuart;

// Function prototypes for packetparser.cpp
uint8_t readPacket (BLEUart *ble_uart, uint16_t timeout);
float parsefloat (uint8_t *buffer);
void printHex (const uint8_t * data, const uint32_t numBytes);

// Packet buffer
extern uint8_t packetbuffer[];

int brightness = 0; // how bright the LED is
int fadeAmount = 10; // how many points to fade the LED by
int highOrNot = 1; // Just a number.
void setup(void) {
Serial.begin(115200);
Serial.println(F(“——————————————-“));

Bluefruit.begin();
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
Bluefruit.setTxPower(4);
Bluefruit.setName(“Bluefruit_AlaskaLinuxUser”);

// Configure and start the BLE Uart service
bleuart.begin();

// Set up and start advertising
startAdv();

pinMode(19, OUTPUT); //19 is blue LED, 17 is red LED.
pinMode(11, OUTPUT);
digitalWrite(11, HIGH);
}

void startAdv(void) {
// Advertising packet
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();

// Include the BLE UART (AKA ‘NUS’) 128-bit UUID
Bluefruit.Advertising.addService(bleuart);

// Secondary Scan Response packet (optional)
// Since there is no room for ‘Name’ in Advertising packet
Bluefruit.ScanResponse.addName();

Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don’t stop advertising after n seconds
}

void loop() {

analogWrite(19, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 50) {
fadeAmount = -fadeAmount;
}
// wait for 500 milliseconds to see the dimming effect
delay(1000);
// To print the brightness // Serial.println(brightness);

// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 – 1023) to a voltage (0 – 3.6V):
float voltage = sensorValue * (3.6 / 1023.0);
// print out the value you read:
if (voltage >= 0.2) {
Serial.print(“Pin A01: “);Serial.println(voltage);
} else {
Serial.println(“No voltage on pin A01.”);
}

if (highOrNot > 0) {
digitalWrite(11, HIGH);
highOrNot = highOrNot -1;
} else {
digitalWrite(11, LOW);
highOrNot = highOrNot +2;
}
}

All of this came, more or less, straight from the guide on setup. However, I did notice that it had the generic name, so I changed the Bluefruit.setName line to something a little more “me”. The rest of the sketch is the same information as I had before.

Here you can see it show up in the Bluefruit LE app on my phone:

Now I am working on sending data to the board. And that I accomplished like so:

void loop(void) {

analogWrite(19, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 50) {
fadeAmount = -fadeAmount;
}
// wait for 500 milliseconds to see the dimming effect
delay(1000);
// To print the brightness // Serial.println(brightness);

// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 – 1023) to a voltage (0 – 3.6V):
float voltage = sensorValue * (3.6 / 1023.0);
// print out the value you read:
if (voltage >= 0.2) {
Serial.print(“Pin A01: “);Serial.println(voltage);
} else {
Serial.println(“No voltage on pin A01.”);
}

if (highOrNot > 0) {
digitalWrite(11, HIGH);
highOrNot = highOrNot -1;
} else {
digitalWrite(11, LOW);
highOrNot = highOrNot +2;
}

// Wait for new data to arrive
uint8_t len = readPacket(&bleuart, 500);
if (len == 0) return;

// Buttons
if (packetbuffer[1] == ‘B’) {
uint8_t buttnum = packetbuffer[2] – ‘0’;
boolean pressed = packetbuffer[3] – ‘0’;
Serial.print (“Button “); Serial.print(buttnum);
if (pressed) {
Serial.println(” pressed”);
analogWrite(17, 50);
} else {
Serial.println(” released”);
analogWrite(17, 0);
}
} else {
Serial.println(packetbuffer[1]);
}
}

So now, when I open the Bluefruit app, and select my “Bluefruit_AlaskaLinuxUser” board, I can choose the controller option. Essentially, I hijacked the controller button portion of the app, and when you press a button on the controller it now lights up the red LED light! When you release the button, the light goes out! Great!

Linux – keep it simple.

Project prep: Digital output on the Bluefruit feather!

img_20180110_0809261094712420.jpg

While I continue to prepare for my big project, I still have a few more things to test. Namely, I need to test the digital outputs to make sure that I understand how to use them. So, I wrote this little ditty to get the job done. Note that I just tacked this onto the end of my previous work.

#include <bluefruit.h>

int brightness = 0; // how bright the LED is
int fadeAmount = 10; // how many points to fade the LED by
int highOrNot = 1; // Just a number.

void setup() {
pinMode(19, OUTPUT); //19 is blue LED, 17 is red LED.
pinMode(11, OUTPUT); //19 is blue LED, 17 is red LED.
// initialize serial communication at 9600 bits per second:
Serial.begin(2400);
digitalWrite(11, HIGH);
}

void loop() {
analogWrite(19, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 50) {
fadeAmount = -fadeAmount;
}
// wait for 500 milliseconds to see the dimming effect
delay(1000);
// To print the brightness // Serial.println(brightness);

// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 – 1023) to a voltage (0 – 3.6V):
float voltage = sensorValue * (3.6 / 1023.0);
// print out the value you read:
if (voltage >= 0.2) {
Serial.print(“Pin A01: “);Serial.println(voltage);
}

if (highOrNot > 0) {
digitalWrite(11, HIGH);
highOrNot = highOrNot -1;
} else {
digitalWrite(11, LOW);
highOrNot = highOrNot +2;
}
}

With the multi-meter hooked up to pins 11 and pin ground on the Bluefruit, I was able to see my program in action. So, during the loop of the program, it checks the number “highOrNot” (sounds like a bad drug joke). If the number is greater than 0, then make pin 11 a HIGH output, or in this case, 3.3 vdc. Also, if it is greater than 0, minus one from the number for the next loop.

As the loop runs again, the number will eventually drop to 0. When it does, add 2 to the number and make pin 11 LOW, or 0 vdc. This turns off the digital pin. Notice that I also increased the loop delay to every second, rather than 1/2 seconds. So, my multi-meter was dancing with 3.3 vdc for two seconds, then 0 for 1 second, on a continuous loop. Spiffy, huh?

Linux – keep it simple.

Project prep: Testing analog input on my Bluefruit Feather!

I’m getting ready to use my Bluefruit Feather in a big project, well, big to me anyways. Before I do that, however, I needed to test a few things to make sure that I understand how it works. So, I added to my “cylon eye” sketch that I made last time, to include communication via serial (over USB) and taking an analog reading over pin A0. Here’s my sketch:

 

int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

void loop() {
analogWrite(LED_BUILTIN, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 80) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(100);
// To print the brightness // Serial.println(brightness);

// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 – 1023) to a voltage (0 – 3.3V):
float voltage = sensorValue * (3.3 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}

I simply modified the Arduino sketch and added it to my already made cylon eye sketch. The user interface on this thing is incredibly easy! All I am doing here is setting up the USB to accept serial input at a baud rate of 9600 (plenty fast enough for the tiny bits of information I am transmitting). Then I take a reading off of pin A0, which comes off of the center tap of a 100k pot. The positive and ground are provided from the boards own 3.3 volt dc supply and ground pin, respectively.

Now I need to test if I can use this as a multi-meter. I grabbed a D cell battery and used my handy dandy alligator clips to hold everything in place. So on my potentiometer, I attached the left side to the negative terminal on the battery, and the right side to the positive side of the battery. The center tap of the pot still goes to the A0 pin, but now, I am not connected to the 3.3 volt dc supply on the board. However, to make this work, you need a common ground, so I still have the board ground hooked to the negative terminal of the battery. Cycling the pot revealed my results, spanning from 1.45 to 0 volts dc!

batt_multi

Try not to laugh too hard at my quick sketch, I just wanted to make sure that you understood what I was saying. Think of pin A0 as the red wire of your multi-meter, and pin ground as the black wire of your multi-meter.

So far, so good. I still need to test a few more things before I can move forward with my project. Perhaps in my next post I can outline the details of what I hope to accomplish.

Linux – keep it simple.

Getting permission to program the Bluefruit Feather board in Ubuntu

bf_f_1st program

I am learning more every day by simply trying to play with my new toy: a Bluefruit Feather board! As I mentioned before, my brother got this little gadget for me as a Christmas present, and it has been a lot of fun to play with!

I was having a bit of trouble uploading my program to it, though, until I figured out my problem. Since this took me a while, I thought I would share it with you, so perhaps you can save a little bit of time on this issue.

TL,DR: Make sure you add your username to the dialout group, so you will have permission to use the ttyUSB0 interface.

I was attempting to upload a little program (the default beginner program, slightly tweaked to change the blink time) to the board. I had the drivers installed, I could hook to the board and pull the boards data, but I couldn’t upload the new program to it.

I kept getting an error that suggested I needed to put the device in DFU mode, but that didn’t turn out to help me. The issue was simply one of permission. My username did not have permission to use the ttyUSB0 interface. So, usermod myself into the dialout group, and after logging out and back in, I was good to go!

Here is the little program that I uploaded to the board:

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(5000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

It just causes the red led to flash for 5 seconds, turn off for 1 second, and repeat endlessly. It worked great! But, that wasn’t cool enough…. So I looked over some examples and made it fade in and out with this code:

 

int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
analogWrite(LED_BUILTIN, brightness);

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

Now I have my own mini Cylon with a glowing, fading red eye saying, “By your command!” (Okay, so I may be having way too much fun with this….)

Linux – keep it simple.

Setting up the Arduino-IDE for the Bluefruit Feather in Ubuntu

arduino1.8.5

There are a lot of neat tools available to program/hack/reprogram/work with this nifty little Bluefruit Feather board! One of them is the Arduino-IDE, a development environment that allows you create and then flash your new programs to the board. I was faithfully following along in the Bluefruit Feather Arduino setup instructions, which are here:

https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/arduino-bsp-setup

But I ran into an issue right out of the gate with step #1: Install the Arduino-IDE. In the instructions it states that it must be version 1.6.12+, something that I missed the first go around. Using Ubuntu’s regular package manager, I just used apt-get install to download  and install the Arduino-IDE.

When I moved on to the next step, where you are to put in the “Additional Board Manager URL”, I ran into a snag. There was no place to do that. The block that should have been displayed there in the preferences didn’t exist. So I re-read the instructions. Turns out that the Ubuntu repository only has Arduino-IDE version 1.0.5! So it was a little out of date.

Fortunately, on the bsp setup page above, there was a direct link to download and install the newer version of the software. A quick download, unzip/untar, and a quick $ sh ./install.sh command allowed me to install the latest version in minutes. Hopefully you can avoid that same pitfall. Now, back to those instructions….

Linux – keep it simple.

Having trouble building Bluefruit LE app in Android Studio?

While playing with my Bluefruit Feather, I decided to build the Android app straight from the source code, so I could see the ins and outs of how it works. Unfortunately, when I downloaded the source code and loaded it into Android Studio, I noticed that it didn’t compile the gradle files correctly.

Turns out that they updated the gradle files for Android Studio 3. My Linux distribution was still using Android Studio 2.3.3. That may see pretty out of date, but it went from 2.3 straight to 3.0.

So, I had two choices, update my Android Studio manually, or downgrade the Bluefruit LE app. Fortunately, Github allows you to view a repository at a previous commit level. So, I loaded up the commit just before they updated the gradle files, and downloaded the repository at that state. I figured if you are reading this, you might want that too, so here is a direct link:

https://github.com/adafruit/Bluefruit_LE_Connect_Android/tree/175d517b3e964a2862f311c75bea740075cafe05

bluefruit_le

Downloaded, unzipped, loaded with Android Studio 2.3.3, and ta-da! It worked! I like easy problems. In the future, however, I will need to update my Android Studio anyways, but for now, this gets me where I need to be. Perhaps by the time I need to update, the Linux version I am using will have that package available pre-built.

Linux – keep it simple.