<< return to Pixycam.com

I want to hook my Pixy to an atmega128.

I want to hook my Pixy to an atmega128.
I refer to your porting guide.
This is the getByte () I wrote. I will use SPI.

extern uint8_t getByte(uint8_t out){
PORTB &= ~0x10; // SS Low
SPDR = out;
while (!(SPSR & 0x80)); // !(SPSR & 0x80) = False : Complete transmission
PORTB |= 0x10; // SS High
return SPDR;
}

Is this right?

and

I want to drive the stepper motor with x value.
I know that g_blocks have parameters.
This is the main() I wrote.

int main(void){
init_SPIset();
init();
unsigned char StepData[4] = {0x01,0x04,0x02,0x08};
unsigned char CntStep = 0;
PORTB |= 0x10; // SPI SS pin set
DDRB = 0x16;
DDRA = 0x0F;
SREG |=0x80; // Global Interrupt Enable
uint16_t a=0;
while(1){
getBlocks(1000);
for(unsigned char i = 0; i<100 ; i++){
if(g_blocks[i].signature == 1){
a = g_blocks[i].x;
}
if(a>= 150){ // move 4 step
CntStep = 0;
PORTA = (PORTA & ~0x0F) | StepData[CntStep];
CntStep++;
delay_ms(1);
PORTA = (PORTA & ~0x0F) | StepData[CntStep];
CntStep++;
delay_ms(1);
PORTA = (PORTA & ~0x0F) | StepData[CntStep];
CntStep++;
delay_ms(1);
PORTA = (PORTA & ~0x0F) | StepData[CntStep];
delay_ms(1);
}
}
}
return 0;
}

The step motor is not running.
Is it the wrong way to use g_blocks?

Hello Jeong,
I’m not an expert on the ATMEGA128. Can you run the Arduino firmware on it?

Edward