Show Posts
Pages: [1]
1  Using Arduino / Audio / Re: Problem with sending MIDI CC messages on: August 04, 2012, 10:40:38 pm
I had the same problem with something similair on my project too when using Arduino 1.0 and later.
Adding (byte) will help the compiler as sending as a byte instead sending a high order byte and a low byte.

From the post which PaulS helped me
Quote returns an int, with the error value in the high order byte, and the data in the low order byte. If you know that the function will not return an error, and you should because you have called Serial.available() and are only calling when there is something to read, then you should be storing the result in a byte sized variable, not a multibyte variable.

After that I began reading the changelog of Arduino >1.0  what actually has changed.

Asfar as I know this worked for my project adding (byte)

void midiCC(byte CC_data, byte c_num, byte c_val){

2  Using Arduino / Programming Questions / Re: UnoJoy + Software Serial & PS2 Library on: July 31, 2012, 08:48:02 am
Well, I don't know yet why those two doesnt work. right now I 'm using two arduino's for my project to archive this >_>.
I have the feeling one of them is changing a timer, atleast I read that software serial uses a interrupt, while ps/2 lib uses alot of delayMicroseconds. I think the problem might be in there, but im not sure.

Now i've just added a second arduino, one to merge the keypad and mouse to serial, > sends over to the 2nd arduino with UnoJoy on it, that arduino translates it to joystick value's to my pc.
expensive way but ok.

I'm not that skilled with programming yet, though it can be done with a single arduino.

Also when coding the serial stuff.. seems like Serial.write(123); is broken in Arduino 1.0.1 ?
I just want to send a byte with the value 123, but when receiving that byte, it just gave me a random value..

int inByte =;

using this gave me weird value's. unless I used Arduino 021.
But this is already solved for me, using an older version of arduino ide.
3  Using Arduino / Programming Questions / Re: UnoJoy + Software Serial & PS2 Library on: July 30, 2012, 07:00:53 pm
I've dissected some codes.. and it's SoftwareSerial cant work with PS/2 mouse library..
Can somebody tell me why?

4  Using Arduino / Programming Questions / UnoJoy + Software Serial & PS2 Library on: July 30, 2012, 05:15:03 pm
Hi there,,

I've been stressing alot since it's weird that the microprocessor just crash for random reasons.
Now what I want to build is a Keypad + Mouse in one house as a Joystick.
I used 2 other library's, the Software Serial, and a PS2 Library without scroll stuff.

The software serial is used for a Keypad which outputs serial at 57600 bps, and the keys are outputted like 11-29, value 0-1 >(131 = key 13 is pressed).
The PS/2 library is used for a mouse on PS/2.
and UnoJoy from

Now I met serveral problems with it when combinding it all together.. first one, keypad works fine, but the mouse movements freeze after a random 5 seconds. It seems the timer is still running while the *void loop* has been stopped/crashed.
So I edit some value's, well actually deleting the delaymicroseconds in the ps2.c, right now the mouse is working fine, but whenever I press a key on the keypad, the arduino crashes instantly. Like they are seperated from functions but crashes the loop :/.

If I put very long delays between the keypad readings and mouse readings, then it works halfy. so if I press rapidly on the keys, the arduino crashes after a few seconds.

I hope someone can help me out, and im stll trying things atm.
Here's my code. (yes its a mess, I've sketched from existents example's.)

Main Script:


#include <ps2.h>
#include "UnoJoy.h"
#include <SoftwareSerial.h>

SoftwareSerial mySerial(16, 17); // RX, TX
PS2 mouse(15, 14);
 //Ints used for keypad
  word inByte;  // I dont know why I used *word* but seems to work, the keypad was programmed on Bascom with Atmega32.
  int key;
  int keyvalue;
  unsigned int keybuffer[30];

 // ints used for mouse
  int mstat;
  int mx;
  int my;

void mouse_init()
  mouse.write(0xff);  // reset;  // ack byte;  // blank */;  // blank */
  mouse.write(0xf0);  // remote mode;  // ack

void setup(){
pinMode(13, OUTPUT);  // Led output
 mySerial.begin(57600);  // softserial
  mouse_init();  //ps2 library


void loop(){
digitalWrite(13, digitalRead(13) ^ 1);   // Activity, if the loop/arduino crashes.. the LED doesnt blink or stays static on.

  // Get keyboard info from SoftwareSerial, because the hardware serial is used by UnoJoy atmega16u2
  if (mySerial.available() > 0) {
    // read the incoming byte
  word inByte =;

 if(inByte > 10 && inByte < 30){ // If it is a key, assign to key.
  // Serial.println("hoi");
   key = inByte;

 inByte =;
 if(inByte < 2){  //if it is a value, assign to a value. aka On/ Off
  keyvalue = inByte;

for(int ki=10; ki <= 30;ki++){ //Puts the keypad keys in a array.
  if(key == ki){
  keybuffer[ki] = keyvalue;

 // get mouse info

  mouse.write(0xeb);  // give me data!;      // ignore ack
  mstat =;
  mx =;
  my =;
// Always be getting fresh data
  dataForController_t controllerData = getControllerData();

dataForController_t getControllerData(void){
  // Set up a place for our controller data
  //  Use the getBlankDataForController() function, since
  //  just declaring a fresh dataForController_t tends
  //  to get you one filled with junk from other, random
  //  values that were in those memory locations before
  dataForController_t controllerData = getBlankDataForController();
  controllerData.triangleOn = keybuffer[25];
  controllerData.circleOn = keybuffer[15];
  controllerData.squareOn = keybuffer[18];
  controllerData.crossOn = keybuffer[17];
  controllerData.dpadUpOn = keybuffer[23];
  controllerData.dpadDownOn = keybuffer[27];
  controllerData.dpadLeftOn = keybuffer[28];
  controllerData.dpadRightOn = keybuffer[12];
  controllerData.l1On = 0; //muis
  controllerData.r1On = 0; //muis
  controllerData.l2On = keybuffer[11];
  controllerData.r2On = keybuffer[13];
  controllerData.l3On = keybuffer[29];
  controllerData.r3On = keybuffer[26];
  controllerData.selectOn = keybuffer[24];
  controllerData.startOn = keybuffer[22];
  controllerData.homeOn = keybuffer[14];

  if(keybuffer[16] == 1){
controllerData.leftStickY = 0;

if(keybuffer[20] == 1){
  controllerData.leftStickY = 255;

if(keybuffer[20] == 0 && keybuffer[16] == 0){
 controllerData.leftStickY = 127;
if(keybuffer[16] == 0 && keybuffer[20] == 0){
  controllerData.leftStickY = 127;

if(keybuffer[19] == 1){
  controllerData.leftStickX = 0;

if(keybuffer[21] == 1){
  controllerData.leftStickX = 255;

if(keybuffer[21] == 0 && keybuffer[19] == 0){
  controllerData.leftStickX = 127;
if(keybuffer[19] == 0 && keybuffer[21] == 0){
  controllerData.leftStickX = 127;

  controllerData.rightStickX = 127 + mx * 4;
  controllerData.rightStickY = 127 + my * 4;
  // And return the data!
  return controllerData;

UnoJoy.h is left alone. no edits ~.
SoftwareSerial is not edited, and I only removed the delaymicroseconds at the ps2 library. (I know it shouldnt be deleted but my mouse still works for somereasons)

I'm not really super skilled in C yet, but i'm a learning person so I hope to get some advice and tips ~

5  Using Arduino / Audio / Re: Sending MIDI CC with Potentiometer issues on: February 22, 2011, 09:48:45 pm
I have the same problem as yours, although you may replace the last line into the if statement ~

  for(int loope = 0;loope < 4; loope++){
 readadc[loope] = analogRead(loope)/8; //reads value from pot
 if(readadc[loope] != readadctemp[loope]){
 MIDI_TX(176,loope,readadc[loope]); //sends cc
 readadctemp[loope] = readadc[loope]; //old value

So it won't update the old value after you changed the pot, it might also speed up your code abit.
Although I think this problem exist since the ADC cant decide on what value it wants to be, for as example
2.5v = 511
2.51v = 512
due 10 bit resolution?
(Im using more inputs using a for loop for that, you can leave that away if you only using one.)

Also, not trying to hijacking your topic... but do you experience glitches when sending cc or notes to your midi device?
It appears at mines that theres alot of garbage sended along with the CC messages, such as "System reset" (FF) random notes. or random hex stuff ~.
This by using MIDI OX on a windows PC and a usb midi cable. (brandless) The cable works fine on normal midi devices, except the arduino.

(Sorry if my english grammar is crappy ^_)

6  Forum 2005-2010 (read only) / Troubleshooting / Re: polyphonic piano with arduino?? on: February 23, 2010, 05:30:23 pm
err, Tone can only do 3 tones at the same time right? because of the limited hardware timer. (on the ATMEGA328)
7  Forum 2005-2010 (read only) / Exhibition / Atmidi - an arduino midi synth. on: March 06, 2010, 09:09:50 am
Hi there,

I made some simple synth which can output midi messages to tone.
since a friend made some software in windows that plays midi files with squarewaves and other things in it.

This midi synth can do 3 ~ 6 tones at the same time using a Midi usb cable (yes it can also connected to a midi keyboard ^^). theres some bugs with hanging notes though. I'm not a skilled C programmer, but I tried to understand it.

This is the result with 3 tones at the same time, reading the channel, note and velocity by a LCD screen.

the 6 notes atst. will be uploaded someday if I have time.
Pages: [1]