1

I'm working with lightblue bean. I have a device that writes data to an SD card on a long button press and switches what will be written (from a list of 5 items) on short button press.

The output, printed both to the SD card and to serial looks like this:

12:38, 7/15/15, subway
12:55, 7/15/15, subway
12:38, 7/15/15, bus
12:55, 7/15/15, rail

etc. It's basically a time stamp then a vale from this list:

char* modes[]= {"walking", "subway", "bus", "railroad", "other"};

This works perfectly. But the bean has very few pins:

enter image description here

  • 5 SCK -- connected to SD card.
  • 4 MISO -- connected to SD card.
  • 3 MOSI -- connected to SD card.
  • 2 SS -- connected to SD card.
  • 1 -- input button, takes long and short presses
  • 0 --
  • A1 SDA --- connected to real time clock for timestamp
  • A0 SCL --- connected to RTC (real time clock) for timestamp

I have one free DIGITAL pin. I need to let the user know what they have selected. This could be done with 5 LEDs that light up next to the user's choice, or maybe displayed text? This is a portable item so a servo that points to the user's choice might be too unreliable.

I've done some research into shift registers. They all seem to need 3 digital pins min. If I could do it with 2 I could rework the button...

Ideas?

  • 1
    Have you considered morse code? ;) – Majenko Jul 15 '15 at 23:09
  • Use SPI to send data to a shift register (or several) to drive LEDs, or 7-segment displays, etc. The free pin becomes the latch signal to the shift registers. SPI is a bus, use it like one. – CrossRoads Feb 23 at 1:38
2

The 7-segment display board is all very well, but that displays 4 digits. That isn't exactly 5 LEDs. In any case that board has a chip on it, if you are going to buy another chip you may as well get an Attiny and use that. Just have serial input (same as the 7-segment board did).

On the Attiny you have 8 pins, 3 of which will be reserved: Vcc, Gnd, Reset. That leaves you with 5 for the communications and the 5 LEDs. So, use one pin for incoming serial, or two pins for SDA/SCL, and use the remaining 3 pins for the LEDs. You can can use Charliplexing to use 3 pins to light up to 6 LEDs.

Charliplexing schematic

For the fun of it, I made up an example using my Uno (it still only uses 3 pins to light 6 LEDs).

Charliplexing demo

There are 3 x 100 Ω resistors as in the schematic. One is completely hidden by the LEDs (leading from the middle yellow wire to the middle pins of the LEDs).

Code:

const byte X1 = bit (2);   // D2 on Uno
const byte X2 = bit (3);   // D3 on Uno
const byte X3 = bit (4);   // D4 on Uno

const byte patterns [7] [2] = {
// PORT DDR
  { 0,   0, }, // all off
  { X1, X1 | X2 }, // LED1: X1 on,  X2 off, X3 HiZ
  { X2, X1 | X2 }, // LED2: X1 off, X2 on,  X3 HiZ
  { X2, X2 | X3 }, // LED3: X2 on,  X3 off, X1 HiZ
  { X3, X2 | X3 }, // LED4: X2 off, X3 on,  X1 HiZ
  { X1, X1 | X3 }, // LED5: X1 on,  X3 off, X2 HiZ
  { X3, X1 | X3 }, // LED6: X3 on,  X1 off, X2 HiZ
};

void setup ()
  {
  }  // end of setup

void loop ()
  {
  for (int i = 0; i < 7; i++)
    {
    DDRD = patterns [i] [1];
    PORTD = patterns [i] [0];
    delay (500);
    }  // end of for loop
  }  // end of loop

The code displays each of the 6 LEDs (plus all off) in a cycle. For each one it configures the DDR (data direction register) plus the PORT (output register) appropriately to light the desired LED.

It works perfectly, except that you may need to work out which LED is which by experimentation.

4

Seems you have I²C on the board you could possibly use an I²C LCD backpack, like from breakouts if you already have an LCD, this means you can have the RTC and display on the I²C bus and probably more things.

Another option seems you mentioned LEDs, you could still use the I²C bus and use an I/O expander and hook LEDs up to that and address them over the I²C. You can use a PCF8575(16 I/O), as there are Arduino libraries. There are breakouts for it. Or you could make your own from another AVR, like one from the ATTiny line, seems there is 5 LEDs.

A I²C bus example: enter image description here
(source: ermicro.com)

Seems you want to use the PWM, you can use a dot/bar driver IC, such as the LM3914 it takes an analog value and shows it as a point on the strip of LEDs, example below: enter image description here

The IC can also work down to 3V.

What you will need to do is add a low pass filter to convert the PWM to a smooth analog value. You will add this in place of the input circuitry(D1 & C1) there:

enter image description here

If there is any confusion on the LM3914, there are quite a few tutorials on google.

  • l2C takes two pins in addition to power and ground-- both of the options you mention take as many pins as a shift register. I might just need to redesign.... – futurebird Jul 15 '15 at 19:30
  • I'm giving you credit for helping but maybe my question should have been more clear. – futurebird Jul 15 '15 at 19:43
  • @futurebird I2C uses the same two pins which you are using, it is a bus? You can use both the RTC and a display option together. What's wrong with that? – RSM Jul 15 '15 at 20:06
  • l2C takes two pins in addition to power and ground - you share the same two pins. Each device on the I2C bus has its own address. That answer was perfectly feasible. – Nick Gammon Jul 15 '15 at 20:37
  • 1
    The peak detector on the original '3914 circuit may work fine as a LPF. – Ignacio Vazquez-Abrams Jul 16 '15 at 1:20
0

I've found a solution! 7-segment display breakout board.

I

This works art 3.3v which is critical for a lightblue bean. I think a servo might be the most creative solution.

I'm still convinced there must be some way to use PWM...

  • It looks like that particular board (can) use async serial, thus the one-wire solution (plus power and ground) will use serial output to drive it. – Nick Gammon Jul 15 '15 at 20:37
  • If you're going to use that board then you may as well use the MCU on it and dump the Bean. – Ignacio Vazquez-Abrams Jul 16 '15 at 1:18
  • The bean has very nice BLE (bluetooth) I'd rather not drop that feature. – futurebird Jul 28 '15 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.