Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I was wondering if anyone can help me out with converting the example Shiftbrite ardino code into Python so I can run it on my Rpi. Here is the example code in question:

int datapin  = 10; // DI
int latchpin = 11; // LI
int enablepin = 12; // EI
int clockpin = 13; // CI
unsigned long SB_CommandPacket;
int SB_CommandMode;
int SB_BlueCommand;
int SB_RedCommand;
int SB_GreenCommand;

void setup() {
   pinMode(datapin, OUTPUT);
   pinMode(latchpin, OUTPUT);
   pinMode(enablepin, OUTPUT);
   pinMode(clockpin, OUTPUT);

   digitalWrite(latchpin, LOW);
   digitalWrite(enablepin, LOW);
}

void SB_SendPacket() {
   SB_CommandPacket = SB_CommandMode & B11;
   SB_CommandPacket = (SB_CommandPacket << 10)  | (SB_BlueCommand & 1023);
   SB_CommandPacket = (SB_CommandPacket << 10)  | (SB_RedCommand & 1023);
   SB_CommandPacket = (SB_CommandPacket << 10)  | (SB_GreenCommand & 1023);

   shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket >> 24);
   shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket >> 16);
   shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket >> 8);
   shiftOut(datapin, clockpin, MSBFIRST, SB_CommandPacket);

   delay(1); // adjustment may be necessary depending on chain length
   digitalWrite(latchpin,HIGH); // latch data into registers
   delay(1); // adjustment may be necessary depending on chain length
   digitalWrite(latchpin,LOW);
}

void loop() {

   SB_CommandMode = B01; // Write to current control registers
   SB_RedCommand = 127; // Full current
   SB_GreenCommand = 127; // Full current
   SB_BlueCommand = 127; // Full current
   SB_SendPacket();

   SB_CommandMode = B00; // Write to PWM control registers
   SB_RedCommand = 1023; // Maximum red
   SB_GreenCommand = 0; // Minimum green
   SB_BlueCommand = 0; // Minimum blue
   SB_SendPacket();

   delay(250);

   SB_CommandMode = B00; // Write to PWM control registers
   SB_RedCommand = 0; // Minimum red
   SB_GreenCommand = 1023; // Maximum green
   SB_BlueCommand = 0; // Minimum blue
   SB_SendPacket();

   delay(250);

   SB_CommandMode = B00; // Write to PWM control registers
   SB_RedCommand = 0; // Minimum red
   SB_GreenCommand = 0; // Minimum green
   SB_BlueCommand = 1023; // Maximum blue
   SB_SendPacket();

   delay(250);
}

I have never written a python program before but I would really like to get the example code working so I have something to build on.

share|improve this question
    
Why you want that in Python? It is already C, although it uses the libraries for the Arduino, it might be easier to port those to the RPi platform (only the library calls used in your program, to start with). But because it relies on the hardware from the AVR micro controllers, not everything can be ported 1-on-1. The more I look at the code, the more I think that starting from scratch is the best and fastest solution. –  ikku Nov 7 '12 at 14:48
    
I suggest you follow the Python tutorial, and then look at some other questions around the site such as raspberrypi.stackexchange.com/q/13/35 –  Alex L Nov 12 '12 at 8:10
add comment

1 Answer 1

I found the following Arduino like library.It should be fairly easy to rewrite the code above for raspberry pi without much modifications with the help of the link above without you getting into python.

Hope it helps.

share|improve this answer
    
Would you pull a bit of the information from the page into your post, to help in case of link rot? –  bearbin Feb 9 '13 at 8:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.