Other posts on my project:
http://www.element14.com/community/tags#/?tags=quadcop_project
I am working on a real update for my project. I have several parts connected up and nearly 1000 lines of C code written for my arduino and my Raspberry Pi2. I have some things to demonstrate and some explanations to do.
I decided to take a tangent and work with the ChipKit Pi. I remember a few years back I wanted a Chip Kit UNO because it was a 32 bit processor that is much faster than the AVR used in the Arduino, however I never got around to it. I didn't recognize what Element14 had sent me until I looked at it closer! I am very excited to own one of these.
I have been testing some code on an Arduino nano328 to read my radio's PWM signals and communicate via I2C to my Raspberry Pi2. Things are working great so I spent some time seeing if I can get the same code to run on the ChipKit. The code compiled with minimal changes. I used the MPIDE on the Raspberry pi to compile it.
As a quick test, I ran a simple speed test on all 3 parts involved and here is a video outlining my results. This is the FIRST video blog I have ever done so bare with me, they will get more polished over time. Watch the video and read some more comments below. I kept wanting to call the ChipKit Pi the ChipKit UNO so you will hear me pause every time I say it.
https://www.youtube.com/watch?v=4tPfn6qDRAs&feature=youtu.be
To summarize:
ChipKit Pi: 98ms
Arduino Nano: 4350ms
Raspberry Pi 2: 15ms
Notes
Phantom I2C objects
Serial pins are different for uploading sketches and for viewing output from Serial.print statements.
Wire.read() is Wire.receive() in the ChipKit version. I commented the wire parts out int eh CHipKit Pi code below.
I am not certain the MPIDE is turning on compiler optimizations. Will research.
Speed increase of the ChipKit Pi: 44.3 times faster.
The Raspberry Pi2 is 6.5 timers faster than the ChipKit pi, and 290 times faster than the Arduino.
Keep in mind this is just a purely simple processing test and ignore I/O and other functionality.
PS: QuadCOP parts get tomorrow, the FUN stuff including all the motors and the frame! Should be able to do a test flight (manual, no pi etc.) this weekend.
Raspberry Pi Code (use time command to get results):
#include <stdio.h>
int main()
{
int a;
int b;
b = 1;
int l1 = 100;
int l2 = 10000000;
for(int i=0;i<100;i++)
for(a = 0;a <=3000;a++)
{
b = b + a;
b = b * 2;
b = b % 1657;
}
printf("Result: %d\n",b);
return 0;
}Arduino Code: (spits out information on serial)
#include <Wire.h>
int lastAnswer;
void receiveEvent(int howMany)
{
}
void requestEvent()
{
Wire.write(lastAnswer); // respond with message of 6 bytes
// as expected by master
}
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent);
Serial.begin(9600);
}
void loop()
{
Serial.println("starting test");
unsigned long ms = millis();
int a;
int b;
b = 1;
int l1 = 17;
int l2 = 3000;
for(int i=0;i<100;i++)
{
for(a = 0;a <=3000;a++)
{
b = b + a;
b = b * 2;
b = b % 1657;
}
}
lastAnswer = b;
ms = millis() - ms;
//printf("Result: %d\n",b);
Serial.println("test completed");
Serial.print("Answer: ");
Serial.println(b);
Serial.print("Time: ");
Serial.println(ms);
}
Chip Kit Pit code:
int lastAnswer;
void receiveEvent(int howMany)
{
}
void requestEvent()
{
//Wire.write(lastAnswer); // respond with message of 6 bytes
// as expected by master
}
void setup()
{
//Wire.begin(4); // join i2c bus with address #4
//Wire.onReceive(receiveEvent); // register event
//Wire.onRequest(requestEvent);
Serial.begin(9600);
}
void loop()
{
Serial.println("starting test");
unsigned long ms = millis();
int a;
int b;
b = 1;
int l1 = 17;
int l2 = 3000;
for(int i=0;i<100;i++)
{
for(a = 0;a <=3000;a++)
{
b = b + a;
b = b * 2;
b = b % 1657;
}
}
lastAnswer = b;
ms = millis() - ms;
//printf("Result: %d\n",b);
Serial.println("test completed");
Serial.print("Answer: ");
Serial.println(b);
Serial.print("Time: ");
Serial.println(ms);
}