I'm working on a project using an open-source BlinkM firmware alternative called cyz_rgb. As far as I know, it duplicates the BlinkM in every aspect except for a few minor details. Otherwise, for all practical measures, it can be used as if I had an actual BlinkM. I'm guessing most have not worked with this before (though possibly with BlinkMs), so my goal here is basically to show my code and seeing if there's any obvious errors that I'm making.
I have the ATTiny45 chip flashed and hooked to a project board with a PIC 18F4520 and using PCW PIC-C's compiler.
So far, I can get all the built-in functions to work using the general call address (LED = 0x00), but I'm having issues with assigning an address and referencing the pixel by that address (though I think the former would cure the latter).
The project board has an LCD screen and I have it display both variables LED and getLED. LED properly displays the address, as it should, but I keep getting 0xFF for the returned getLED value. There is only one pixel attached, so both the Set_Address() and Get_Address() functions should work using the general broadcast channel.
The PIC chip uses a 7-bit address (0-127), with the LSB being a R/W instruction. I'm not sure if the pixel interprets Set_Address(0x02) as address 2 or 1 (assumes it was already bit-shifted). However, I used 0x02 since it's an even number and should avoid the slave thinking it a write command.
I've also tried changing the parameters from 'int' to 'unsigned char', but I still get the same getLED result of 0xFF.
I don't have a schematic of the setup, but I have pull-up resistors on both SCL and SDA and everything has a common ground. I assume the circuitry is correct though since it works fine other than addressing? I can make one if necessary though.
One other note: as I said, I can get the following code to work using LED = 0x00; however, before it will start, I have to cycle the power to the chip, i.e. unplug the power, then plug it back in. Not sure why this is happening.
Main C code:
Library Functions:
I have the ATTiny45 chip flashed and hooked to a project board with a PIC 18F4520 and using PCW PIC-C's compiler.
So far, I can get all the built-in functions to work using the general call address (LED = 0x00), but I'm having issues with assigning an address and referencing the pixel by that address (though I think the former would cure the latter).
The project board has an LCD screen and I have it display both variables LED and getLED. LED properly displays the address, as it should, but I keep getting 0xFF for the returned getLED value. There is only one pixel attached, so both the Set_Address() and Get_Address() functions should work using the general broadcast channel.
The PIC chip uses a 7-bit address (0-127), with the LSB being a R/W instruction. I'm not sure if the pixel interprets Set_Address(0x02) as address 2 or 1 (assumes it was already bit-shifted). However, I used 0x02 since it's an even number and should avoid the slave thinking it a write command.
I've also tried changing the parameters from 'int' to 'unsigned char', but I still get the same getLED result of 0xFF.
I don't have a schematic of the setup, but I have pull-up resistors on both SCL and SDA and everything has a common ground. I assume the circuitry is correct though since it works fine other than addressing? I can make one if necessary though.
One other note: as I said, I can get the following code to work using LED = 0x00; however, before it will start, I have to cycle the power to the chip, i.e. unplug the power, then plug it back in. Not sure why this is happening.
Main C code:
Rich (BB code):
#include <18F452.h>
#use delay (clock = 20000000)
#fuses HS, NOWDT, NOLVP
#use I2C (MASTER, SDA=PIN_C4, SCL=PIN_C3)
#include "..\Library\modifiedlcd.h"
#include "..\Library\functions.h"
void main(){
int LED = 0x02, getLED;
lcd_init();
Set_Address(LED); // Set pixel address
getLED = Get_Address();
printf(lcd_putc,"\f LED: %X \n getLED: %X", LED, getLED);
while(1){ // Blink light on/off every second
Goto_RGB_Now(LED,255,255,255);
delay_ms(1000);
Goto_RGB_Now(LED,0,0,0);
delay_ms(1000);
}
}
Rich (BB code):
/**************************
Go to RGB Color Now
**************************/
void Goto_RGB_Now(int LED, int red, int green, int blue){
i2c_start(); // i2c start condition
i2c_write(LED); // Device address
i2c_write(0x6E); // Goto RGB color now
i2c_write(red); // Red value
i2c_write(green); // Green value
i2c_write(blue); // Blue value
i2c_stop();
}
/**************************
Set Address
**************************/
void Set_Address(int LED){
i2c_start();
i2c_write(0x00);
i2c_write(0x41);
i2c_write(LED);
i2c_write(0xD0);
i2c_write(0xD0);
i2c_write(LED);
i2c_stop();
delay_ms(20); // Wait for EEPROM to write
}
/**************************
Get Address
**************************/
int Get_Address(){
int address;
i2c_start();
i2c_write(0x00);
i2c_write(0x61);
address = i2c_read();
i2c_stop();
return address;
}
Last edited: