Arduinome + Trellis project help

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
nortonw3
 
Posts: 19
Joined: Sat Jul 19, 2014 12:45 pm

Arduinome + Trellis project help

Post by nortonw3 »

OK, so Ive got my Ardu LEO working on my OONTZ running the sequencer from the OONTZ library, but i want it to do more. Ive looked into turning it into a monome but run into problems with the code written by brianlight. HERE:

Code: Select all

/***************************************************
 * This is an implementation of the 40h Protocol used by the Monome
 * ----> http://monome.org
 *
 * Brian Lightfoot
 * 03.21.2014
 * [email protected]
 *
 *
 * Designed specifically to work with the Adafruit Trellis
 * ----> https://www.adafruit.com/products/1616
 * ----> https://www.adafruit.com/products/1611
 *
 *
 *
 *
 *
 ****************************************************/



#include <Wire.h>
#include <Adafruit_Trellis.h>
#include <Adafruit_Trellis_XY.h>


Adafruit_Trellis matrix0 = Adafruit_Trellis();
Adafruit_Trellis matrix1 = Adafruit_Trellis();
Adafruit_Trellis matrix2 = Adafruit_Trellis();
Adafruit_Trellis matrix3 = Adafruit_Trellis();

Adafruit_TrellisSet trellis =  Adafruit_TrellisSet(&matrix0, &matrix1, &matrix2, &matrix3);

#define NUMTRELLIS 4

#define numKeys (NUMTRELLIS * 16)

#define INTPIN A2

//-----------------------------------------------------------
// define offsets for 4X4 Tiles
struct TileOffsets TileOffsets =
{
	{
		0, 4, 0, 4, 0, 0, 0, 0
	}
	,
	{
		0, 0, 4, 4, 0 , 0, 0, 0
	}
};

uint8_t xVal;
uint8_t yVal;
uint8_t xyTrellisID;

// These variables are used to handle the ADC messages, and store which ports are currently enabled,
// and which are not.
byte ADCnum;
byte ADCstate;
byte ADCEnableState[4];


int  ShutdownModeVal, address, command = 0 ;
boolean ShutdownModeChange = false, WaitingCommand = true;
byte byte0, byte1, row = 0;
byte keyState[8];
byte x;
byte y;
long nextRefresh;

int chessboard[8][8] =
{
	{
		12, 8, 4, 0, 44, 40, 36, 32
	}
	,
	{
		13, 9, 5, 1, 45, 41, 37, 33
	}
	,
	{
		14, 10, 6, 2, 46, 42, 38, 34
	}
	,
	{
		15, 11, 7, 3, 47, 43, 39, 35
	}
	,
	{
		28, 24, 20, 16, 60, 56, 52, 48
	}
	,
	{
		29, 25, 21, 17, 61, 57, 53, 49
	}
	,
	{
		30, 26, 22, 18, 62, 58, 54, 50
	}
	,
	{
		31, 27, 23, 19, 63, 59, 55, 51
	}
};

void setup()
{
	Serial.begin(115200);

	pinMode(INTPIN, INPUT);
	digitalWrite(INTPIN, HIGH);

	trellis.begin(0x72, 0x73, 0x70, 0x71);

	for (uint8_t i = 0; i < 8; i++)
	{
		for (uint8_t j = 0; j < 8; j++)
		{
			trellis.setBrightness(j);
			trellis.setLED(chessboard[i][j]);
			trellis.writeDisplay();
			delay(50);
		}
		trellis.setBrightness(1);
	}


	for (uint8_t i = 0; i < numKeys; i++)
	{
		trellis.clrLED(i);
	}
	trellis.writeDisplay();
}
void onLED( byte x, byte y)
{
	byte xMask = 1 << x;
	trellis.setLED(chessboard[y][x]);
}

void offLED( byte x, byte y)
{
	byte xMask = (1 << x) ^ 0xff;
	trellis.clrLED(chessboard[y][x]);
}
void clearRows()
{
	for(byte y = 0; y < 8; y++) chessboard[8][y] =  0;
}

void setRows()
{
	for(byte y = 0; y < 8; y++) chessboard[8][y] =  0xff;
}

void checkSerial()
{
	byte x, y, state;
	do
	{
		if (Serial.available())
		{
			if (WaitingCommand)        // command is the first byte of the two byte command
			{
				byte0 = Serial.read();
				command = byte0 >> 4;
				WaitingCommand = false;

				switch(command)  // do one byte commands
				{
					case 9: // clear command
						if((byte0 & 1) == 0) clearRows();
						else setRows();
						WaitingCommand = true; // next byte is a new command
						break;
				}

				if((command > 9) || (command < 2))  WaitingCommand = true; // command outside range so must be an error
			}

			else
			{
				WaitingCommand = true;    // the next byte is the first byte of the next command
				byte1 = Serial.read();    // read the second byte of this command

				switch(command)
				{

					case 2:  // LED command
						state = byte0 & 0x0f;   // is the command for on or off
						x =  ((byte1 >> 4) & 0x07);  // mask so we don't go over the 8 by 8 grid
						y =  ((byte1 & 15) & 0x07);

						if (state == 0)
						{
							offLED(x, y);
						}
						else
						{
							onLED(x, y);
						}
						break;

					case 3:   // led intensity command
						break;
					case 4:  // led test command
						if( (byte1 & 1) == 0)
						{
							setRows();
						}
						else
						{
							clearRows();
						}
						break;
					case 5:  // enable ADC command - but we don't do this
						break;
					case 6: // shutdown command - not sure what the monome is expected to do here
						ShutdownModeChange = true;
						ShutdownModeVal = byte1 & 15;
						break;
					case 7:  // led row command
						y = byte0 & 0x07; // mask this value so we don't write to an invalid address.
						x = 0;
						for(byte i = 0x1; i != 0x0; i <<= 1 )
						{
							if( (i & byte1) != 0)
							{
								onLED(x, y);
							}
							else
							{
								offLED(x, y);
							}
							x++;
						}
						break;

					case 8:  // coloum command
						x = byte0 & 0x07; // mask this value so we don't write to an invalid address.
						y = 0;
						for(byte i = 0x1; i != 0x0; i <<= 1 )
						{
							if( (i & byte1) != 0)
							{
								onLED(x, y);
							}
							else
							{
								offLED(x, y);
							}
							y++;
						}
						break;
					default:
						onLED(7, 7);
						break;

				} // end switch(command)
			} // end of else in if(WaitingCommand)
		} // end of if(Serial.available();
	} // end of do
	while (Serial.available() > 8);  // keep on going if we have a lot of commands stacked up
}

void checkButtons()
{
	if (trellis.readSwitches())
	{
		for (uint8_t i = 0; i < numKeys; i++)
		{
			if (trellis.justPressed(i))
			{
				// button debounce
				delay(50);
				int s = 1;
				TrellisToXY(i, TileOffsets, &xVal, &yVal);
				Serial.write((0 << 4) | (s & 15));
				Serial.write((yVal << 4) | (xVal & 15));
			}
			if (trellis.justReleased(i))
			{
				int s = 0;
				TrellisToXY(i, TileOffsets, &xVal, &yVal);
				Serial.write((0 << 4) | (s & 15));
				Serial.write((yVal << 4) | (xVal & 15));

			}
		}
	}
}

void sendADC(int port, int value) {
  Serial.write((1 << 4) | ((port << 2) & 0x0C) | ((value >> 8) & 0x03));
  Serial.write(value & 0xFF);
}


int current[4]; 
int previous[4]; 
int tolerance = 7;


void checkADCs()
{
	for (int adcCounter = 1; adcCounter < 3; adcCounter++)
  {

    if (ADCEnableState[adcCounter] != 0)
    {
      current[adcCounter] = analogRead(adcCounter);

      if (abs(previous[adcCounter]-current[adcCounter]) > tolerance)
      {
        previous[adcCounter] = current[adcCounter];
        sendADC(adcCounter,current[adcCounter]);
      }

    }

  }
}

void loop()
{
	checkButtons();
	checkSerial();
	checkADCs();
	trellis.writeDisplay();
}





I have all the correct libraries installed but the errors keep popping up like this:
sketch_jul24a:42: error: variable 'TileOffsets TileOffsets' has initializer but incomplete type
sketch_jul24a.ino: In function 'void checkButtons()':
sketch_jul24a:277: error: 'TrellisToXY' was not declared in this scope
sketch_jul24a:284: error: 'TrellisToXY' was not declared in this scope
I dont know what to do. Ive read about flashing a serial number to the arduino or something about 40h protocol. What am i missing? i honestly dont know whats going on because the code seems to work for everyone else.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduinome + Trellis project help

Post by adafruit_support_mike »

Where is the function 'TrellisToXY()' supposed to be defined?

Neither the Adafruit_Trellis library nor the Gkuetemeyer Adafruit_Trellis_XY library contain a function with that name.

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: Arduinome + Trellis project help

Post by pburgess »

Adafruit_Trellis_XY is a third-party library for handling Trellis X/Y-to-button-number conversion...it can be downloaded at https://github.com/Gkuetemeyer/Adafruit_Trellis_XY

User avatar
brianlight
 
Posts: 38
Joined: Mon Dec 23, 2013 9:52 pm

Re: Arduinome + Trellis project help

Post by brianlight »

Yes you will need the trellisXY library above & you've grabbed an older version of the Arduino sketch try this sketch by Robin Stubbs https://github.com/rbnstubbs

NOTE!!!!! THIS WILL NOT WORK WITH SERIALOSC
Use Robin Stubbs modified monomecereal max patch

Need to get this running first test included demo programs
serial-pyio http://sourceforge.net/projects/serial-pyio/
Use the version in git or svn

If your using Linux you must modify devicedetector.py search for the line with ttyUSB and change to ttyACM.

If your using Windows you must point serial-pyio to your Arduino Com port when adding your device in settings..

Once you have serial-pyio running & tested & working then try some of the older non serialosc monome max patches found here http://monome.org/docs/app:monomeserial:list

Along the lines of non monome related things have you checked this sketch out yet?
https://github.com/CollinCunningham/OONTZ_Arpy

User avatar
nortonw3
 
Posts: 19
Joined: Sat Jul 19, 2014 12:45 pm

Re: Arduinome + Trellis project help

Post by nortonw3 »

so, ive got the code working with monomecerial.maxpat and the trellis-monome-test.maxpat but when i launch another application like plane or monome-sum they dont work. why is this?

*i switched the arduino leonardo out with an uno and now it is working.

User avatar
na0s
 
Posts: 3
Joined: Wed Jun 19, 2013 12:11 am

Re: Arduinome + Trellis project help

Post by na0s »

It is an unfortunate side effect of the current firmware. Your device is emulating a 40h monome (the first version ever available) but most patches are being made for the current versions (using SerialOSC). For some reason the OSC message addresses is different. The patches are looking for /prefix/press [x] [y] [on/off] but monomecerial is putting out /prefix/grid/key [x] [y] [on/off]. LEDs are being sent as /prefix/led [x] [y] [on/off] but need to be received as /prefix/grid/led/set [x] [y] [on/off].

My solution so far has been to manually edit all the patches I want to use so that they look for and send the right messages. But someone more familiar with Max and with OSC might be able to create an intermediary patch to translate the messages.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”