electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Arduino
Esplora -> 2xCV + Trigger
Post new topic   Reply to topic
Page 1 of 1 [8 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Mon Jan 07, 2013 11:07 pm    Post subject: Esplora -> 2xCV + Trigger
Subject description: Or at least that's the goal....
Reply with quote  Mark this post and the followings unread

I got an Esplora over the weekend, and while distracting myself from a misbehaving Baby-8 Sequencer, decided to use a 2 channel 12 bit SPI DAC I had lying around (MPC4922) to use the Esplora as a CV generator.

I want each axis of the joystick to be one CV, and the rightmost button on the diamond as trigger. I intend to scale the two axes by setting the slider and clicking the top and bottom buttons on the diamond (haven't decided which is X and which is Y yet). And for future fun I'll make the fourth button change modes, indicating mode with the RGB LED at the lower right.

Even though I think this should work with just the one chip, I am still somewhat space constrained, so I glued three cheap jacks together and glued them to the board.

Then I got silly and figured that one of the targets for this is my cigarlab+ which has CV in for pitch on two oscillators, but most other control voltages are bananas, so i glued/soldered two bananas to the two CV outputs. Obviously there are grounding issues so using them will require me to plug in the 1/4" jack for the trigger, even if I don't use that trigger mode.


All this is built and planned, but not one bit of coding yet Smile. Hopefully in the next week....


2013-01-07_21-59-40_708.jpg
 Description:
Top View before jacks
 Filesize:  322.82 KB
 Viewed:  517 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.

2013-01-07_21-59-40_708.jpg



2013-01-07_23-53-41_365.jpg
 Description:
Looking down the barrel
 Filesize:  422.55 KB
 Viewed:  459 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.

2013-01-07_23-53-41_365.jpg



2013-01-07_23-53-56_379.jpg
 Description:
flying over
 Filesize:  435.03 KB
 Viewed:  454 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.

2013-01-07_23-53-56_379.jpg



2013-01-07_23-54-10_235.jpg
 Description:
and behind
 Filesize:  451.93 KB
 Viewed:  425 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.

2013-01-07_23-54-10_235.jpg


Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Tue Jan 08, 2013 9:57 pm    Post subject: Reply with quote  Mark this post and the followings unread

aaand success Smile At least good enough to call done for now, I implemented all the ideas I wanted to, though they could probably be done more gracefully or perhaps in a more musically useful way.

Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Wed Jan 09, 2013 8:29 pm    Post subject: Reply with quote  Mark this post and the followings unread

Theory of Operation:

The Joystick controls two control voltages, one for each axis.

The slider is used in conjunction with the up and down buttons on the button pad to set the Y and X axis voltage ranges, respectively. You set the slider to some approximation of how "wide" you want the range to be, and then hit the respective X or Y axis button.

The left button changes the mode.

The right button is the trigger/gate button.

In Mode 0, the LED is red, and the right button sends a trigger out the trigger jack (10ms I believe, 5V).

In Mode 1, the LED is green, and the right button is a gate, so the trigger jack sends out 5V until you release the button.

In Mode 2, the LED is blue, but there's nothing configured to do anything... yet Smile I was thinking of firing some kind of arpeggiation, or perhaps if the slide has limited the range, let you set an offset voltage, so that the lower left isn't always 0V, 0V on the CV jacks. Or maybe simply center whatever the range is, we'll see.



Code:

/*
 * set up to use MCP4922 on board taking over LCD slot to generate CVs
 *
 *
 */

#include <Esplora.h>
#include <SPI.h>

/*
  This array holds the last sensed state of each of the buttons
  you're reading.
  Later in the code, you'll read the button states, and compare them
  to the previous states that are stored in this array. If the two
  states are different, it means that the button was either
  pressed or released.
 */
boolean buttonStates[4]; // only care about the 4 diamond buttons

/*
  This array holds the names of the buttons being read.
  Later in the sketch, you'll use these names with
  the method Esplora.readButton(x), where x
  is one of these buttons.
 */
const byte buttons[] = {
  SWITCH_RIGHT,
  SWITCH_LEFT,
  SWITCH_UP,
  SWITCH_DOWN,
};

const byte X = 0;
const byte Y = 1;

int scaling[2];
int mode = 0;      // values 0==trigger 1==gate, 2==uncommitted
int modes = 3;
int modeRed[] = {
  180, 0, 0
};
int modeGreen[] = {
  0, 140, 0
};
int modeBlue[] = {
  0, 0, 180
};


#define mySS 3
#define myTRIG 11

void setup() {
  // initialize serial communication:
  // Serial.begin(9600);
  for (byte thisButton=0; thisButton<4; thisButton++) {
    buttonStates[thisButton] = false;
  }
  scaling[Y] = 1;
  scaling[X] = 1;

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  // Default is DIV4, or 4MHz for an AVR at 16MHz system clock
  SPI.setClockDivider(SPI_CLOCK_DIV2); // MCP4922 should be able to go up to 20MHz or even 32MHz
                                       // but half the system clock is as fast as we can go
  SPI.setDataMode(SPI_MODE0); //just to be sure.
 
  // alternate SS
  pinMode(mySS, OUTPUT);
  digitalWrite(mySS, HIGH);
  pinMode(myTRIG, OUTPUT);
  digitalWrite(myTRIG, LOW);
  modeLED(mode);
  //delay(20);  // setup time??
}


void loop() {
  // Iterate through all the buttons:
  for (byte thisButton=0; thisButton<4; thisButton++) {
    boolean lastState = buttonStates[thisButton];
    boolean newState = Esplora.readButton(buttons[thisButton]);
    // if button, do action
    if (lastState != newState) {
      if (!newState) { // Button press down; normally high
        switch (thisButton) {
          case 0:  do_trigger(newState);
                    break;
          case 1:  change_mode();
                    break;
          case 2:  scale(Y);
                    break;
          case 3:  scale(X);
                    break;
        }
      } else if ((mode == 1) && (thisButton == 0) && newState) {
          do_trigger(newState);
      }
    }
    // Store the new button state, so you can sense a difference later:
    buttonStates[thisButton] = newState;
  }
 
  // read X & Y from Joystick
  // joystick goes from -512 to +512, center is 0
  // the direction is opposite expectations, hence the - instead of +
  int xAxis = ((512 - Esplora.readJoystickX()) / scaling[X]) - 1;
  int yAxis = ((512 - Esplora.readJoystickY()) / scaling[Y]) - 1;
  if (xAxis<0) {
    xAxis = 0;
  }
  if (yAxis<0) {
    yAxis = 0;
  }
 
  // write X & Y to DAC
  doDAC(X, xAxis);
  delay(10); // give  some time to settle, may not be necessary
  doDAC(Y, yAxis);
  delay(10); // give  some time to settle, may not be necessary
}

void do_trigger(boolean state) {
  if (mode == 0) {
    digitalWrite(myTRIG, HIGH);
    delay(10);
    digitalWrite(myTRIG, LOW);
    delay(10);
  } else if ((mode == 1) && (!state)) {
    digitalWrite(myTRIG, HIGH);
    delay(10);
  } else if ((mode == 1) && (state)) {
    digitalWrite(myTRIG, LOW);
    delay(10);
  }
}

void change_mode() {
  mode = (mode + 1) % modes;
  modeLED(mode);
}

void scale(int axis) {
  // note that slider high value is to the left, we want the reverse behavior
  int slider = Esplora.readSlider();
  if (slider > 1023) {
    slider = 1023;
  }
  scaling[axis] = 1024 / (1024 - slider);
  //Serial.print("Slider: ");
  //Serial.println(Esplora.readSlider());
  //Serial.print("Scale factor: ");
  //Serial.println(scaling[axis]);
}

void doDAC(byte port, int value) {
  // port 0 == A on DAC, port 1 == B on DAC
  // value is 1-1024, needs to be scaled up *4 but limited to 4095
  value *= 4;
  //Serial.print("port: ");
  //Serial.print(port);
  //Serial.print("  value: ");
  //Serial.println(value);
  switch (port) {
    case 0: value |= 0x3000; //select channel A, gain = 1
          break;
    case 1: value |= 0xB000; // select channel B, gain = 1
          break;
  }
  digitalWrite(mySS, LOW); // manual slave select
  SPI.transfer(highByte(value));
  SPI.transfer(lowByte(value));
  digitalWrite(mySS, HIGH);
}

void modeLED(int mode) {
  Esplora.writeRGB(modeRed[mode], modeGreen[mode], modeBlue[mode]);
}



esplora-cv-sch.png
 Description:
 Filesize:  13.26 KB
 Viewed:  456 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.

esplora-cv-sch.png



Last edited by elmegil on Wed Jan 09, 2013 8:35 pm; edited 2 times in total
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Wed Jan 09, 2013 8:33 pm    Post subject: Reply with quote  Mark this post and the followings unread

Not posting stripboard because 1) mine is a bastard thing and 2) I don't have a stripboard editor that I like and don't have patience to go find one right now. The important thing is that the two 10-pin pin headers that mate with the Esplora have 20 columns between them (not inclusive), so they'd be column 1 and column 22, and that nothing of either is used except for the 3rd and 4th pins of the right header.
Back to top
View user's profile Send private message
bubzy



Joined: Oct 27, 2010
Posts: 594
Location: United Kingdom
Audio files: 64

PostPosted: Thu Jan 10, 2013 12:13 am    Post subject: Reply with quote  Mark this post and the followings unread

looks cool man, the video doesnt work tho :/
_________________
_Richard_ Smile
Back to top
View user's profile Send private message
PHOBoS



Joined: Jan 14, 2010
Posts: 5591
Location: Moon Base
Audio files: 705

PostPosted: Thu Jan 10, 2013 5:33 am    Post subject: Reply with quote  Mark this post and the followings unread

video works fine for me Cool
_________________
"My perf, it's full of holes!"
http://phobos.000space.com/
SoundCloud BandCamp MixCloud Stickney Synthyards Captain Collider Twitch YouTube
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Thu Jan 10, 2013 6:04 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks Smile

I wonder what's up with the video, it works here too.
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Fri Jan 25, 2013 9:50 am    Post subject: Reply with quote  Mark this post and the followings unread

Correction to the schematic, VERY IMPORTANT

PUT 1K OUTPUT RESISTORS ON THOSE JACKS!

I fried my D11 output when attempting this with my modular rather than my cigarlab.

I've hacked a different solution onto mine, but don't make the same mistake Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1 [8 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Arduino
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use