BlueFruit Project: All boxed in!

Spent a little bit of time with a soldering iron.

 

I put my project into a box, wired in all of the relays, and ran several feet of wire for connecting to the various functions. Hopefully this will work! I’m planning to do some heavy bench testing really soon.

schematic

This was my original  schematic. For the most part, I stuck with it, but I did make a few changes along the way. For one, I replaced the second analog input to be a digital input, just routing the brake lights to activate a relay which allows 3.3vdc to go to the input switch.

Another change was adding a parking lights relay, which is activated from the “key on” relay. I don’t have it hooked up in my box yet, but it is in place, just needs the power wire hooked to it. It wasn’t part of the original plan, so I am not implementing it yet. I don’t want to get too crazy before actually testing if it works.

It is going to be really fun to hook this up. I’ll have to crawl around under the dash of my truck and get these wires put in.

Linux – keep it simple.

Advertisements

BlueFruit Project: Added kill on too many start attempts

One of the perks of bench testing your newfangled autostart project is that you can start to see patterns of use that may lead to trouble. The other is that when you hook up a multi-meter to the relays with the diode audio turned on, you can listen to the hum of your machine!

IMG_20180424_122308

One such test, though, proved insightful. One would surmise that if you attempt to start the vehicle, that after the prescribed number of attempts, it would simply give up and stop. However, my code only stops it from cranking after the three failed attempts. That means the accessory/fuel pump relays are still on!

I realized this when the hum from the multi-meter didn’t stop. But it should have.

While you can check out the whole commit on my GitLab, but here is the relevant portion:

if (startTimer == 0 && startAttempts > 0) {
digitalWrite(11, LOW);
digitalWrite(15, HIGH);
crankTimer = 3;
startTimer = -1;
Serial.println (” crankTimer ON “);
} else if (startTimer == 0 && startAttempts == 0) {
// Turn everything off from to many attempts.
digitalWrite(16, LOW);
digitalWrite(15, LOW);
digitalWrite(7, HIGH);
digitalWrite(11, HIGH);
crankTimer = -1;
startTimer = -1;
runTimer = -1;
startAttempts = -1;
Serial.println(” Kill All – Too many attempts. “);
} else if (startTimer > 0) {
startTimer = startTimer -1;
Serial.print (” startTimer “); Serial.println(startTimer);
}

Before, if the startTimer reached zero, it would check if the startAttempts was greater than, or equal to zero, and then try to crank. Now, I have it only attempt to crank if the startAttempts is greater than 0. If it is 0, it will send the kill signal and stop all attempts.

Short and simple, but that’s usually the best kind of fix!

Linux – keep it simple.

BlueFruit Project: Stage 1 Relays!

autostart

Blinking lights! Yes, the first prototype of the first stage relay setup for my home made autostart is assembled. As you know, a small 3 to 5 vdc BlueFruit Feather can’t crank an engine starter. That’s just too much current to flow through such a small board. To make this work, I have to step up through relays in stages to get to the big relays that can actually do the work.

So, stage 1 relays are actually Latching Relay Featherwings that are joined to the BlueFruit feather via soldered wire connections. These latching connections only need about 10ms of signal to turn on or off the 3.3 vdc relays, which will hold the 12 vdc power supply to the stage 2 relays.

The stage 2 relays will then use minimal current at 12 vdc to drive the vehicle relays that actually engage things like the key on and cranking power. Don’t worry, at the end of the project I will follow this up with a diagram and parts list. Looks like the overall price is about $60 worth of material, pending finding a used container or box for free.

Linux – keep it simple.

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.