I am trying to use the DUE as data logger. I started with UNO but was too slow.
Using the Programming port everything is OK. However (as with UNO), it is not fast enough, as I am limited by the baudrate.
I was aware of it, it was just to check. The idea was to use the native port, which should be a USB3.0, so support higher speeds.
But guess what... it is not working. I do load the code correctly on to the DUE using the native port (at least, that's what the Arduino IDE tells me). But when I try to read the data from a Python script, it is like nothing is happening! I tried also println, but nothing was coming through either...
Just in case, I am using PySerial (Python-Anaconda, under Linux, Ubuntu18.10 to be precise).
So it seems like nothing is going to the PC when using the native port...
Any ideas???
My Arduino code is the following:
const int analogPin = A0;
unsigned long t, dt;
const unsigned long t_1hr = 3600000000;
int t_ht, V;
byte buf2[2],buf1[4];
//-------------------------------
void setup() {
analogReadResolution(12);
SerialUSB.begin(115200); // Initialize Native USB port
t = micros();
t_ht = -1;
}
//-------------------------------
void loop() {
dt = micros()-t; // calculate elapsed time
V = analogRead(analogPin);
t += dt;
// I use negative for t_ht, so I can used the fact it is negative to know when the data starts //
if (t >= t_1hr) { t_ht -= 1; t = t-t_1hr;};
SerialUSB.write(t_ht);
buf1[0] = t & 255;
buf1[1] = (t >> 8) & 255;
buf1[2] = (t >> 16) & 255;
buf1[3] = (t >> 24) & 255;
SerialUSB.write(buf1, 4);
buf2[0] = V & 255;
buf2[1] = (V >> 8) & 255;
SerialUSB.write(buf2, 2);
}
When I use the Blink example through the Programming port, the led blinks, but when I load using the Native port, no blinking!
I attached a screen shoot to show the output from the IDE saying that the code should have arrived correctly to destination
Update:
If I now change to cable back to the Programming port, the led starts blinking (without doing anything else, no reloading anything). I am a bit confused...
With the programming port, you select Arduino Programing Port in Tools> Board
With the Native USB port, you select Arduino DUE(Native USB port) in Tools>Board
If the basic blink sketch runs correctly when uploaded via the programming port, but not via the Native USB port, something is faulty in the board hardware ---> Ask a refund to your board reseller.
A last try : Upload the basic blink sketch via the programming port, then , change the cable to the Native USB port, then push the reset button: Does the led blinks ?
With the programming port, you select Arduino Programing Port in Tools> Board
With the Native USB port, you select Arduino DUE(Native USB port) in Tools>Board
I am going with care regarding this, so this is not the issue
ard_newbie:
A last try : Upload the basic blink sketch via the programming port, then , change the cable to the Native USB port, then push the reset button: Does the led blinks ?
mmm, I did as asked: and the led blinks!
This gave me an idea for another test:
If I load the sketch thought the programming port and then change the cable to the Native port, the SerialUSB is working!!!
Is this normal on the DUE (I have not read anything like this on the web) or it is just the clone version I got doing strange things???
Well, if the test in reply #10 works, it's a normal behavior
BUT you should be able to upload directly from the Native USB port, this is the normal behavior.
Before uploading, push the Erase button for 3 seconds, then the Reset button for 3 seconds, then select Native USB port, hook your USB cable to the Native USB port, select the correct COM port (COMx(Native USB port). If the correct COM port do not appear in Tools>Port, then unplug/pulg the USB cable until it appears, select it and upload.
I have no idea why, but if I load the sketch using the Programming port, and then change the cable to the Native port things are behaving.
The same behavior for the two units I got (less than $15 each, including cable!).
Just in case someone is interested, I am getting one channel 12Bits ADC reading to the PC at 120KS/s using:
const int analogPin = A0;
int V;
byte buf2[2];
const int pwm_out_pin = 2;
//-------------------------------
void setup() {
// Setup all registers
pmc_enable_periph_clk(ID_ADC); // To use peripheral, we must enable clock distributon to it
adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST); // initialize, set maximum posibble speed
adc_disable_interrupt(ADC, 0xFFFFFFFF);
adc_set_resolution(ADC, ADC_12_BITS);
adc_configure_power_save(ADC, 0, 0); // Disable sleep
adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1); // Set timings - standard values
adc_set_bias_current(ADC, 1); // Bias current - maximum performance over current consumption
adc_stop_sequencer(ADC); // not using it
adc_disable_tag(ADC); // it has to do with sequencer, not using it
adc_disable_ts(ADC); // disable temperature sensor
adc_disable_channel_differential_input(ADC, ADC_CHANNEL_7);
adc_configure_trigger(ADC, ADC_TRIG_SW, 1); // triggering from software, freerunning mode
adc_disable_all_channel(ADC);
adc_enable_channel(ADC, ADC_CHANNEL_7); // just one channel enabled
adc_start(ADC);
pinMode(pwm_out_pin,OUTPUT); // sets the pin as output
analogWrite(pwm_out_pin, 128);
// wait for USB serial port to be connected - wait for pc program to open the serial port
SerialUSB.begin(115200); // Initialize Native USB port
while(!SerialUSB);
}
//-------------------------------
void loop() {
while((adc_get_status(ADC) & ADC_ISR_DRDY) != ADC_ISR_DRDY){}; //Wait for end of conversion
V = adc_get_latest_value(ADC);
buf2[0] = V & 255;
buf2[1] = (V >> 8) & 255;
SerialUSB.write(buf2, 2);
}
The Python code (I use Jupyter, hence the %pylab):
%pylab
import serial
port_str='/dev/ttyACM0'
ser_arduino = serial.Serial(
port=port_str,
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
buffer_size = 2048
Bit1 = zeros((2,buffer_size),dtype=int)
for i in range(0, buffer_size):
Bit1[0,i] = int.from_bytes(ser_arduino.read(), byteorder='big', signed=False)
Bit1[1,i] = int.from_bytes(ser_arduino.read(), byteorder='big', signed=False)
V1 = Bit1[0,:] + Bit1[1,:]*2**8
dt_period = mean(diff(where(abs(diff(V1))>1000)))
period = 500e-6 # Measured at the oscilloscope
dt = period/ dt_period
print('The avg time step is [us]:',dt*1e6)
print(1e-3/dt,'KS/s')
Pklaus claims 1MS/s, but his python code is not working in my machine and when I try to use my python code to read the data of his sketch, the data I am getting in the Python side is not correct. I have no more time to spend on this... maybe another time.