Connecting the LKM1638 board


#1

Now that I've finished writing my book, it's time for me to build some actual instruments with Axoloti. I'll use this topic to document the process of connecting the LKM1638 board, so you have a starting point if you are interested in building an instrument with it.

You can buy these boards for around €7 at DealExtreme. The specs of these boards:

  • 8x 7-segment display
  • 8x double-color green/red LED
  • 8x button

A great thing is that the boards can be chained, so you could use two of them to create a 16-step sequencer. The boards use the SPI bus on the Axoloti, so you will only need 4 GPIO ports.

Creating Objects
My goal is to develop some objects to work with this board. Some ideas:

  • Send text to the 7-segment display
  • Use the buttons as toggles, LEDs will show which toggle is on/off
  • Use the buttons as a mini keyboard to play notes
  • Use the buttons to toggle notes on/off in a sequencer.

A good starting point to work with this board, and create objects is this old test patch made by @johannes.

If you connect the board to the Axoloti Core and run the patch, you'll get something like the photo below. The sel/sel b 16 objects reflect the state of the LEDs. Buttons can be used to cycle through the LED colors.

Circuit Diagram

  • Connect VCC to VDD (RED)
  • Connect GND to GND (Black)
  • Connect STBO to PA4 (Blue)
  • Connect CLK to PA5 (Green)
  • Connect DIO to both PA6 and PA7 (Yellow)

Patches

You'll need to add a gpio/spi/config object to every patch you want to use with this board. These are the settings for the object:

  • clock_polarity: CPOL=0
  • clock_phase: CPHA=0
  • baudrate: FPCLK/128
  • format: LSB first

Toggle Object

The first object I'm working on is a toggle object. The object will output booleans so you can use the 8 buttons on the board as toggles. The LEDs on the board will also reflect the state (on/off) of the toggle. A basic patch for the object looks like the screenshot below, I'll post the object once I'm finished writing code + testing.


Axoloti Control
Volca type drum sequencer
Janvantomme contributions
#2

I ordered two LKM1638 just now and will test with the Axoloti once they arrive. I'm not the best C programmer, just the little bit I've done with Arduinos. I'm much better with Python and MaxMSP. If I can help in any way, please let me know.


#3

I only know the basics of C programming as well. The hardest thing now will be figuring out what functions to use to talk to the board via the SPI port.


#4

Hi Jan, just received the LKM1638 (x2) modules. I played with the .axh file you linked to above and managed to get IO working back and forth between the buttons and LEDS but as you mentioned daisy chaining doesn't work yet. I tried amending the code to extend daisy chaining capability but didn't have any luck, will dig through http://mjoldfield.github.io/pi-tm1638/tm1638_8h.html. I see great potential, especially if we can utilize the displays as well. Have you experimented more with these modules and Axoloti since?


#5

Haven't had the chance to do a lot of programming on the objects lately. Currently building a new dedicated synth with Axoloti that will use one of the LKM1638 boards as a control. When the synth is finished, I'll start programming again.

I'll stick with using one board for now, my second one got damaged while desoldering the connectors. If you want to solder the LKM board directly to the Axoloti, it's better to remove the black plastic part, end solder the wires directly to the pins and bend them over so you can mount it inside a case.

I did some tests with a lasercut top plate and 3D printed buttons as well.


#6

That looks fantastic, bravo! I'm going to take a stab at developing the object to accommodate two LKM1638 boards because my intention is to have a functional 16 step sequencer. Getting both displays working would be overkill, for me at least. I will prioritise the functionality of the LEDs and buttons first. Where did you get your white buttons from? I see what you mean regarding the removal of the 10 pin connector, will try to not fry my second board :stuck_out_tongue:


#7

I designed the white buttons myself, and printed them on my 3D printer. Just a plastic prototype for now, will print them in elastic material when I finish the synth.


#8

Now that I've finished building my synth, I had some time to develop some objects to work with the LKM1638 board. I'll need to clean up the code and document everything a bit better, and then I'll publish them to the community library. This is what I've got so far:

  • Read when buttons are pressed, no LED output.
  • Read when buttons are pressed, LED output.
  • LED output, no button interaction.
  • Use buttons and LEDs as toggles.

The 7-segment display doesn't work yet, but I hope to make that work soon.

Here's some videos of the objects in action.


#9

I've just posted some objects to work with the LKM1638 board to the community library. Feedback is welcome.


#10

A bit hard to see in this smartphone picture, but I've got the display working tonight. Only thing I need to do now is creating a dedicated object to set the text.


#11

Brilliant stuff, Jan! At this point I might be of some help. I'd like to think I'm good at testing and debugging after years of doing web development :wink: Super excited to try this out! You haven't mentioned whether two LKM1638 boards can be daisy chained together yet so I assume there isn't that capability yet. Do you know what's involved to make two units "talk" to one another? I could work on that part. I'm aiming to build a polysynth with built-in 64 step sequencer so 16 toggles would be ideal.


#12

There's no way to control two boards at the same time for now. And I don't plan on developing that since I don't need it for my synth. But I think you can adapt my code if you want to chain two boards.

This is a piece of code from my objects.

void tm1638_send_command(uint8_t x){
	SPID1.spi->CR1 |= SPI_CR1_BIDIOE;
	spiSelect(&SPID1);
	txbuf[0] = x;
	spiSend(&SPID1,1,&txbuf[0]);
	spiUnselect(&SPID1);
}

And this is the same function from this Raspberry PI library. ( https://github.com/mjoldfield/pi-tm1638/blob/master/src/tm1638.c ) You'll notice that the first parameter in this function, the variable t is a reference to a single board when they are chained together.

static void tm1638_send_command(const tm1638_p t, uint8_t x)
{
	bcm2835_gpio_write(t->strobe, LOW);
	delayMicroseconds(1);

	tm1638_send_raw(t, x);
	bcm2835_gpio_write(t->strobe, HIGH);

	delayMicroseconds(1);
}

My code uses the SPI API from the Axoloti firmware, the other code uses a BCM2835 GPIO library for the Raspberry PI that does something similar. You'll probably find a lot of Arduino code to work with the LKM1638 boards online that might help you figure things out.


#13

Hi Jan, I am trying to get the LEDs and the display to work with the objects provided by you. I finally managed to hook this unit up to my axoloti and while the buttons are working, I get no response from neither the LEDS nor the 7-segment displays. I checked the unit with an arduino and it is just working fine.

I am using the example patches together with the exact same unit as shown in the photos, sourced from deal extreme a while ago. Any ideas? Any input appreciated, thanks, Christian


#14

Can you try with this patch Johannes made? I sometimes had to run that one first in order for things to work.


#15

That worked, thanks a lot!


#16

Hi, I put some work into the original objects provided by @janvantomme. It is now possible to update the text display while the object is live. I am using this with a string mux object to display the name of the currently selected patch. I have also added inputs for both LED colors and an inlet to clear the text display.

What I did not manage to solve is that the patch will crash if you update the display too frequently/quickly. I was able to make it more tolerant by adding sleep-commands in a couple of places, this is for sure not the right way to do it. However, this is not a problem for me since I am triggering the patches with a midi floorboard, my feet are slow enough not to exceed the max frequency :wink: if anybody is interested in using this object and is more fund of programming, this can certainly be solved.
Here are the links to the object and an example patch:

lkm 1638 object
lkm 1638 example patch

Thanks to @janvantomme for his work with this display module!


#17

I only know the basics of C programming as well. The hardest thing now will be figuring out what functions to use to talk to the board via the SPI port.


#18

Is it possible yet to chain two LKM1638 boards to get 16 steps and get the both displays to work also? I can't write my own objects. How many gpios would it use?


#19

It's not possible with these objects. Two chained boards will only take up 4 gpio. Code will need some changes to be able to send data to, or read from two boards.


#20

But it is possible to use two of these boards when theyre not chained? How many gpios would they use that way?