#include <Streaming.h>
#include <StopWatch.h>
#include <Albert.h>
#include "avdweb_AnalogReadFast.h"
const byte adcPin = A1;
void setup(void)
{ Serial.begin(9600);
while(!Serial);
Serial << "\nanalogRead_10bit us1 analogRead_12bit us2 analogReadFast_10bit us3 analogReadFast_12bit us4";
for(int i=0; i<10; i++) testAnalogRead();
}
void testAnalogRead()
{ static Stopwatch stopwatch(micros);
//delay(1000);
stopwatch.start();
int adc1 = analogRead(adcPin); // default resolution 10bit 425us on SAMD21
stopwatch.stop(); int t1 = stopwatch.interval;
analogReadResolution(12);
stopwatch.start();
int adc2 = analogRead(adcPin); // 425us on SAMD21
stopwatch.stop(); int t2 = stopwatch.interval;
analogReadResolution(10);
stopwatch.start();
int adc3 = analogReadFast(adcPin); // 23us on SAMD21
stopwatch.stop(); int t3 = stopwatch.interval;
analogReadResolution(12);
stopwatch.start();
int adc4 = analogReadFast(adcPin); // 24us on SAMD21
stopwatch.stop(); int t4 = stopwatch.interval;
Serial << endl << adc1, t1, adc2, t2, adc3, t3, adc4, t4;
analogReadResolution(10); // restore default
}
void loop()
{
}
Hi, this code compiles and uploads for the Arduino Zero. I want to serial print out the stopwatch.interval from this code but I could not figure out. Can anyone help please?
This seems to disobey most of the coding rules for Arduino , plus you’ve not stated your problem anywhere . If you are not a great programmer note that :
Setup - runs once and is for setting things up . Once the code here has run through here once that is it. The Arduino will then sure in void loop , in your case doing nothing .
Loop runs continually and is where your running code should reside
Have a look at simple coms examples in the IDE and build on those
Hi, this code compiles and uploads for the Arduino Zero. I want to serial print out the stopwatch.interval from this code but I could not figure out. Can anyone help please?
...it got stuck inside the code tags.
From the code...
Serial << endl
This construction will print endl to the Serial port. It's rare to see this on Arduino because using the << operator uses a whole lot of memory that most Arduinos don't have.
It might be time to look at some other Serial examples for Arduino. The old methods still work on the Zero.
MorganS:
It's rare to see this on Arduino because using the << operator uses a whole lot of memory that most Arduinos don't have.
No, it doesn't.
For example, using this library, the following code uses uses 12 Bytes of extra flash, and the same amount of RAM.
// #include <PrintStream.h>
void setup() {
Serial.begin(115200);
#ifdef PrintStream_h
Serial << F("Hello, World") << endl;
#else
Serial.println(F("Hello, World"));
Serial.flush();
#endif
}
void loop() { }
Printf uses a ton of memory, the <<-operator does not.
Pieter
Thank you all for your replies and suggestions!! I am still having the trouble to get the serial print out on the serial monitor(Serial plottor). As I mentioned before, the code compiles but there is no out put from the Arduino Zero. Any further helps are greatly appreciated.
Which "streaming" library are you using?
Arduino Zero or "Zero pro" or some other SAMD21? "debug port" or native USB?
Have you tried a simple "Hello World" using the streaming library and your HW setup?
Hi,
Thank you for your suggestions. I have tried all the options as you mentioned above. I am using the Arduino Zero. I downloaded the streaming library form the following link. This library has the example code which compiles and gives the serial output occasionally. It means the example code outputs sometime and does not most of the time.
Where did you get the idea to use the comma operator?
Try this
Serial << value1 << '\t' << value2 << '\t' << value3 << endl;
Thank you all for the suggestions. After spending few days I was able to figure out it. The main problem was the Albert library in the code. After commenting out the #<Albert.h>, I was able to print out the serial output on the serial monitor. If someone is interested, I can post the code in the forum.
raju1234:
If someone is interested, I can post the code in the forum.
Please do, it helps others that might come across this thread in the future, and we may be able to give you tips to further improve the code, for example.