Archive of articles classified as' "arduino"

Back home

Control CD4021 and 74HC595 over the same SPI bus

30/10/2011

Working on a project I needed extra digital in’s and extra digital out’s for my Arduino Uno (lots of LEDs, lots of buttons). I’ll use a CD4021 to extend the digital in’s and a 74HC595 to gain extra digital out’s. I decided it would be best to both access the data of the CD4021 and send data to the 74HC595 over the hardware SPI bus on the Arduino (see previous post). Turns out te be not that hard (fortunately ;) ). Here’s the eagle schematic for 1 4021 and 1 595. Of course you can cascade more IC’s if you need more in’s or out’s. Only difference is that you’ll have to interpret and send more bytes (1 byte per IC).

Here’s my Arduino code so far:

#include <SPI.h>

#define PIN_SCK          13             // SPI clock
#define PIN_MISO         12             // SPI data input
#define PIN_MOSI         11             // SPI data output
#define PIN_SS1          10             // SPI hardware default SS pin, 4021
#define PIN_595_1        9              // SPI 74HC595

// result byte for 4021
byte buttons8;

// global vars for button timeout and debounce
long button1timeout = 0;
long button2timeout = 0;
long debounce = 200;

void setup() {
  Serial.begin(9600);
  SPI.begin();

  // set all IC select pins HIGH
  digitalWrite(PIN_SS1,HIGH);
  pinMode(PIN_595_1, OUTPUT);
  digitalWrite(PIN_595_1,HIGH);
}

void loop() {

  // SS1 = HIGH -> 4021 is gathering data from parallel inputs

  // select 595
  digitalWrite(PIN_595_1,LOW);

  // send BIN number to 595 to light 1 LED (not necessarily the 1 example LED on the schematic)
  SPI.transfer(B00000100);

  // deselect 595
  digitalWrite(PIN_595_1,HIGH);

  // select 4021
  digitalWrite(PIN_SS1,LOW);
  // read CD4021 IC
  buttons8 = SPI.transfer(0x00);

  // button functions and debounces
  // needs refactoring for smaller footprint
  if((B10000000 & buttons8) && (millis() - button1timeout > debounce)) {
    Serial.println("but1");
    button1timeout = millis();
  }
  if((B01000000 & buttons8) && (millis() - button2timeout > debounce)) {
    Serial.println("but2");
    button2timeout = millis();
  }

  // deselect 4021
  digitalWrite(PIN_SS1,HIGH);
}

 

 

 

No Comments

Arduino, CD4021 and SPI

29/10/2011

The “ShiftIn” tutorial on the Arduino site (Parallel to Serial Shifting-In with a CD4021BE) is very clear on why and how to setup and test your Arduino in combination with a CD4021 IC. I needed extra digital inputs and decided to communicate via SPI with the CD4021 chip. Figured it out, it was actually pretty simple thanks to the easy SPI implementation in the Arduino software since version 0020 or so (?)

Setup as described in the Arduino tutorial. Reconnect the clock, the MOSI and the slaveselect as the #defines in the following code. And you’re all set.

#include

#define PIN_SCK          13             // SPI clock
#define PIN_MISO         12             // SPI data input
#define PIN_MOSI         11             // SPI data output
#define PIN_SS1          10             // SPI hardware default SS pin

void setup() {
  Serial.begin(9600);
  SPI.begin();
}

void loop() {
  digitalWrite(PIN_SS1,HIGH);

  // while gathering info from parallel inputs
  // do some other processing
  // for now I'll use
  delayMicroseconds(200);

  // select PIN_SS1 CD4021 IC
  digitalWrite(PIN_SS1,LOW);
  // read byte from CD4021 IC
  Serial.println(SPI.transfer(0x00),BIN);
}

tip: buy some resistor arrays instead of all individual resistors

No Comments

LCD optimizations and additions

25/10/2011

One of my first posts contains a LCD prototype. Today I needed LCD functionality and made some optimizations and additions to the LCD prototype.

Speed up

In the LCD3Wire library, I removed two delays:

131c131
<   //delay(1);
---
>   delay(1);
155c155
<   //delayMicroseconds(1);
---
>   delayMicroseconds(10);

This gives a good speed increase when using the LCD3Wire library. Furthermore, reading this post (http://solar-blogg.blogspot.com/2009/02/displaying-custom-5×8-characters-on.html) I copied the code to the Arduino and displayed my own custom character (using the LCD3Wire library)

lcd.commandWrite(0x40);
lcd.print(0b00000);
lcd.print(0b00100);
lcd.print(0b00010);
lcd.print(0b11111);
lcd.print(0b00010);
lcd.print(0b00100);
lcd.print(0b00000);
lcd.print(0b00000);
lcd.cursorTo(1,0);
lcd.print(0x00);

And another great LCD speedup trick by designer2k2 on the Arduino forums is to avoid using lcd.cursorTo. Instead use his direct positioning code

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1240088162

lcd.commandWrite(0x80);                //Line=1, Cursor 0
lcd.commandWrite(0xC0+val);            //Line=2, Cursor val
lcd.commandWrite(0x94+7);              //Line=3, Cursor 7
lcd.commandWrite(0xD4);                //Line=4, Cursor 0
3 Comments

Progress…

15/03/2011

Long time no post. Sorry, real-life is sometimes getting in the way ;)

Recently I bought a Leaflabs Maple R5 to replace my Arduino’s. I really like it. Eventually I ported ChibiOS (realtime OS) to it and tried some software filter algorithms from musicdsp.org. Didn’t make me happy; 72Mhz isn’t enough to do serious audio filtering (at least not using my prototype coding).

New plan: use the Maple for the VCO’s (kind of DCO). Number of voices to be determined. Anti-aliasing virtual analog oscillator code will be constructed using research by Valimaki and Huovilainen. The first hardware voltage controlled versions of the VCF(s) and VCA(s) will be based on my own research regarding the VCF/VCA filter chip in the Roland Juno series. These original Roland chips last usually 15 to 20 years. Right now I’m working on a to be open sourced hardware version of these filterchips. The VCA part is solved using a BA6110 voltage controlled opamp. These aren’t in production anymore (as I know of) but easily obtainable via ebay. I used mooger5′s very valuable research to construct a BA6110 based VCA. His solution (using an SSM2044 for the VCF part):

mooger5, http://www.electro-music.com/forum/topic-17995-25.html, 15 march 2011

The VCA part like drawn by mooger5 is working perfectly! In the next few weeks (busy, busy) I’m going to start working on a VCF part using the LM13700 OTA. Fingers crossed! Resources are the great courses of Aaron Lanterman (Georgia Tech) and, ofcourse, the 80017 VCF/VCA teardown from obsoletetechnology. When the VCF part is working, my plan is to replace the BA6110 with, probably, a LM13700 OTA. This solution will be the base on which I’ll build my own hardware filter and amplifier.

To be continued!

No Comments

dual arduino :: voice generator & manager

20/12/2010

Looking for an original solution for a voice generator (instead of the Juno 82c54 solution), I decided to dedicate an entire Arduino to voice generation.

Read the rest of this article »

No Comments

waveshaping 101

25/10/2010

Time to start work on waveshaping. My synth is now able to generate 6 voices of musically tuned square waves. Nice, but pretty boring ;). First step is to shape the square wave to a sawtooth wave. This is the square wave from 1 voice:

Inspired by the following waveshaping schematic from the Roland Juno 6,

I came up with the following solution:

The OpAmp is a LM324N, suitable for single +5V power (remember my USB requirement). The transistor is a 2N3904 NPN instead of the PNP used in the Roland schematics. All resistor and capacitor values are determined by the parts I have in my stock. The minus voltage on the capacitor integrator loop is generated via an ICL7660 IC (transforms + voltages into – voltages). Result:

Tada: a sawtooth wave. The peak of the wave is not at 5v because of the maximum output swing of the LM324N OpAmp (+V – 1.5V).

Now I have to find the best values for all the components to generate a normalised saw wave (peak at 3.6v) for all frequencies. My synth should be able to handle all frequencies between 8Hz (midinote 0) and 4000Hz (around midinote 107).

No Comments

the 5v idea

7/10/2010

mmmm what if the entire synth could run on 5v? Just power it over USB. It would make a perfect companion for your laptop but also very easy to install with your desktop PC. The development is also a lot more “portable”. Now I have to work with my own bulky +/-15V power supply. It would be fantastic to just work with an USB cable connection. My MacBook can charge my iPad (1A) so the USB power connection should be powerful enough to drive a (tiny) synthesizer.

Leading to this idea was also the fact that I received my sample MAX7403 8th order lowpass filter chips from Maxim today. These operate at a single 5V power supply  and I think they’ll make great audio filters! Cutoff is addressed via square wave so the Arduino PWM can operate this…

No Comments

re-welcome at sinneb.com ehhh sinneb.net

7/10/2010

Hi all and welcome back,

Because I did not pay in time for my .com domain (I do have some excuses but won’t bore you with them ;) ), it got cancelled and I had to switch to a .net domain. Thinking about it, a .net does actually fit perfectly for this website about the build of a synthesizer. So from now on it’s sinneb.net!

Sorry for the downtime. Let’s get to work!

No Comments

sinneb36 prototype 8: 3 voices polyphony controlled by Arduino!

12/07/2010

Yes, it’s working!

Check out this demo, midi file loaded in Logic > midi out > breadboard > Arduino

Read the rest of this article »

2 Comments

proto 6 and new ideas

5/07/2010

At the bottom of this post you’ll find the newest code for the prototype. This code has some nice enhancements over the previous:

  • A first begin with ADSR code
  • A better midi implementation. The Arduino keeps track of the order of notes played so note-off commands are treated right. A note-off “resounds” the previously played note. If there is no previous note (all notes-off), the output is silent; no note is played. This new implementation also leads to a better legato management.
  • A 128 values linear to logarithmic lookup table to give the ADSR (MCP42100) a musical course.

Sketch for proto 7:

Here I’m going to use 1 dataline and 1 clockline for all components. This saves on the digital out pins from the Arduino. There’s going to be a lot of data shifting through the 4 74hc595′s and the 3 mcp42100′s… A challenge ;)

Read the rest of this article »

No Comments