Here we will show a simple program that is used to computer pi. This experiment can be used to test the computation speed of pcDuino3.
First, we connect the serial port of pcDuino3 to a serial terminal using the UART to USB module. Note: this is not necessary as pcDuino3 can display the data on its terminal. However, to compare with Arduino Uno, we keep the same method.
Copy and paste the following test to the built-in Arduino IDE of pcDuino3:
// // Pi_2 // // Steve Curd // December 2012 // // This program approximates pi utilizing the Newton's approximation. It quickly // converges on the first 5-6 digits of precision, but converges verrrry slowly // after that. For example, it takes over a million iterations to get to 7-8 // significant digits. // // I wrote this to evaluate the performance difference between the 8-bit Arduino Mega, // and the 32-bit Arduino Due. // #include <core.h> // for pcDuino v3 #include "Serial.h" #define ITERATIONS 100000L // number of iterations #define FLASH 1000 // blink LED every 1000 iterations void setup() { pinMode(13, OUTPUT); // set the LED up to blink every 1000 iterations Serial.begin(57600); } void loop() { unsigned long start, time; unsigned long niter=ITERATIONS; int LEDcounter = 0; boolean alternate = false; unsigned long i, count=0; float x = 1.0; float temp, pi=1.0; Serial.print("Beginning "); Serial.print(niter); Serial.println(" iterations..."); Serial.println(); start = millis(); for ( i = 2; i < niter; i++) { x *= -1.0; pi += x / (2.0f*(float)i-1.0f); if (LEDcounter++ > FLASH) { LEDcounter = 0; if (alternate) { digitalWrite(13, HIGH); alternate = false; } else { digitalWrite(13, LOW); alternate = true; } temp = 40000000.0 * pi; } } time = millis() - start; pi = pi * 4.0; Serial.print("# of trials = "); Serial.println(niter); Serial.print("Estimate of pi = "); Serial.println(pi, 10); Serial.print("Time: "); Serial.print(time); Serial.println(" ms"); delay(10000); }
Open the serial port tool of the computer and select the corresponding COM port and the correct baud rate. We can see the returned data printed.
Leave a Reply
You must be logged in to post a comment.