Hi,
A few things with your new code that I am having trouble working with:
1. Only the centipede board outputs are working still. The Arduino I/O pins still aren't working (I have gotten just the centipede shield pins to work in previous years but this time I am hoping to add more so that is why I want to get the regular I/O pins in on the action also.)
2. In the middle, you have
Wire.write(0x00);
Wire.write(0x00);
Wire.write(0x12);
Wire.write(0x00);
Wire.write(0x01);
Wire.write(0x00);
Wire.write(0x13);
Wire.write(0x00);
Wire.endTransmission();
at the end of the void setup() loop. When I try and use that, it gives me an error of "call of overloaded 'write(int)' is ambiguous". Commenting out the lines of Wire.write(0x00) so it looks like the below code fixes this problem and uploads with no errors.
// Wire.write(0x00);
// Wire.write(0x00);
Wire.write(0x12);
// Wire.write(0x00);
Wire.write(0x01);
// Wire.write(0x00);
Wire.write(0x13);
// Wire.write(0x00);
Wire.endTransmission();
3. And this one baffles me the most. It only works occasionally. The first time I tried it, it worked as explained in number 1. Never got hung up and the centipede shield part worked (but not the Arduino I/O). I close everything out, open it back up and try it again and nothing. I haven't changed anything it just won't work. I re-upload the sketch, I confirm the header matches, everything, yet still nothing. I upload my previous code for only 60 channels and run that one and it works no problem. I upload yours and nothing lights up. I keep playing around with it and all of a sudden it works again. I try shutting down everything, and it stops working again and I can't get it back again. I just don't understand why it'll all of a sudden work and then stop without changing anything, just reopening the programs. I checked connections and the board and everything obvious, and I know it isn't any of that cause it works when I upload a different sketch.
Thanks for your help
Hi, try this for the lines in setup:
Wire.write((byte)0x00);
Wire.write((byte)0x00);
Wire.write(0x12);
Wire.write((byte)0x00);
Wire.write(0x01);
Wire.write((byte)0x00);
Wire.write(0x13);
Wire.write((byte)0x00);
Wire.endTransmission();
and this in the main loop:
Wire.write(0x12);
Wire.write((byte)output_A);
Wire.write(0x13);
Wire.write((byte)output_B);
Wire.endTransmission();
It looks like its not sure wether 0x00 is a value or a location, putting (byte) infront confirms it is a value.
I haven't added the outputs on the Arduino yet. I wanted to test the 64 channels first. It should be quite easy to do afterwards as all that is needed is to read another serial value and map it to an output.
EDIT: I've just had a look and it appears I've set this up at the moment for 64 channels. Was it working with a sequence of 64 or more channels and not with a sequence that only had 60?
looks like the centipede shield uses pin 4 and 5 for the I2C communication. Looks like you are trying to use pin 4 and 5 as outputs. Could that be the problem?
kev: the shield uses Analog 4 and 5, I am trying to use Digital 4 and 5 so I do not believe so since they are different.
Barnabybear: I am just using random LEDs attached to the output pins to see if it is working correctly. I just noticed that only half the shield is actually working with this setup. pins 0-7, 16-23, 32-39, and 48-55 work fine. Pins 8, 24, 40, and 56 are always high no matter what. Pins 9-15, 25-31, 41-47, an 57-63 are always low no matter what. So one side of each output is working, and on the other side 1 is high and the other 7 are low.
Also, it is only working with a sequence of 64 or more channels. I tried with 60 and it wasn't working properly.
Hi, cool I'll look into that now do you still have to comment out the lines with
Wire.write((byte)0x00);
or will they compile now?
Once all 64 work fine I can reduce it to 60 and then add the other channels.
Hi,
No it compiles fine now (sorry I should have mentioned that). Also I wasn't having the problem where after I tried to restart the program it wouldn't work, so it's possible that it was fixed with the new addition.
Hi, can you try this please:
Wire.write(0x12);
Wire.write((byte)output_A);
// Wire.write(0x13);
Wire.write((byte)output_B);
Wire.endTransmission();
I hope that will get the other bank working but the order may be wrong i.e. 13->8 instead of 8->13. If it is, its an easy fix.
Hi,
Commenting out that line, the other bank works much better now (but not 100% quite yet...). 2 pins still don't work on the same side of each bank. They are 9,12,25,28,41,44,57, and 60. They are in the same position on each bank.
As you may have guessed by now, I have basically taught all of this to myself, and I have zero idea how you are making all this work but you're awesome and I hope I can learn this much one day.
Thanks
Hi, all being well 3rd time lucky, I’ve split the setup into two blocks as I don’t think it was working correctly as one lump. Try this it should fix all the outputs, what I can’t tell is if the 8 to 15 side is in the correct order.
I’m self-taught as well and will be more than happy to run through how all this works, this is a good write up on using the MCP23017 chip that is on the centipede board, it should help make sense of a lot of the code. http://tronixstuff.com/2011/08/26/tutorial-maximising-your-arduinos-io-ports/
#include <Wire.h>
unsigned int output_A;
unsigned int output_B;
unsigned int read_loop;
unsigned int IC_loop;
void setup() {
Serial.begin(115200);
Wire.begin();
for (IC_loop = 0; IC_loop < 4; IC_loop++) {
switch (IC_loop) {
case 0:
Wire.beginTransmission((byte)0x20);
break;
case 1:
Wire.beginTransmission((byte)0x21);
break;
case 2:
Wire.beginTransmission((byte)0x22);
break;
case 3:
Wire.beginTransmission((byte)0x23);
break;
}
Wire.write((byte)0x00);
Wire.write((byte)0x00);
Wire.write((byte)0x00);
Wire.endTransmission();
switch (IC_loop) {
case 0:
Wire.beginTransmission((byte)0x20);
break;
case 1:
Wire.beginTransmission((byte)0x21);
break;
case 2:
Wire.beginTransmission((byte)0x22);
break;
case 3:
Wire.beginTransmission((byte)0x23);
break;
}
Wire.write((byte)0x12);
Wire.write((byte)0x00);
Wire.write((byte)0x00);
Wire.endTransmission();
}
}
void loop() {
for (;;) {
while (!Serial.available());
if (Serial.read() != 'V') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'I') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'X') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'E') {
continue;
}
while (!Serial.available());
if (Serial.read() != 'N') {
continue;
}
for (IC_loop = 0; IC_loop < 4; IC_loop++) {
output_A = 0;
for (read_loop = 0; read_loop < 8; read_loop++) {
while (!Serial.available());
if (Serial.read() != 0)
bitSet(output_A, read_loop);
}
output_B = 0;
for (read_loop = 0; read_loop < 8; read_loop++) {
while (!Serial.available());
if (Serial.read() != 0)
bitSet(output_B, read_loop);
}
switch (IC_loop) {
case 0:
Wire.beginTransmission((byte)0x20);
break;
case 1:
Wire.beginTransmission((byte)0x21);
break;
case 2:
Wire.beginTransmission((byte)0x22);
break;
case 3:
Wire.beginTransmission((byte)0x23);
break;
}
Wire.write((byte)0x12);
Wire.write((byte)output_A);
Wire.write((byte)output_B);
Wire.endTransmission();
}
//ADD ANY EXTRA CHANNELS HERE
}
}
Which other outputs do you want to use (numbers please), do you want them as analog (PWM) or digital and normal or inverted?
Hi,
This new code seems to be working perfectly – no pins are left on, nothing is getting hung up, etc. For the other pins, I am hoping to use digital output pins 2-13. I only need them digital on/off as I will be sending them directly to SSRs to control lights. Also a normal output since the shield output is also normal.
Thanks
