Go Down

Topic: Native Port (Read 404 times) previous topic - next topic

jpedrego

Dear all,

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:

Code: [Select]

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);
}


jpedrego

Thanks. It does not make sense... In principle I am not doing anything wrong!

I just thought about it now: I suspect strongly that the Due I got it is a clone one... could be related to this?

I will try later on a windows10 machine... just in case.

pert

Start with a very simple sketch to make sure serial communication with the computer is working:
Code: [Select]
void setup() {
  SerialUSB.begin(9600);
}

void loop() {
  SerialUSB.println("hello");
  delay(1000);
}

Upload that sketch and then open Tools > Serial Monitor. Do you see "hello" printed to the Serial Monitor once a second?

jpedrego

I have tried that already (I forgot to mention it) but nothing it is being printed in the "Serial Monitor".

I just tested again on a Lubuntu18.04 machine I have lying around... (before was on Lubuntu18.10)

In any case, thanks for trying to help Pert!

pert

Are you certain the USB cable is plugged into the Native USB jack on the Due?:

jpedrego

Oh came on...., I am not that newbie!!!  :smiley-wink:

Also, the Arduino IDE is sending the code to it correctly... (at least it is what is telling me)

jpedrego

#7
May 14, 2019, 06:12 am Last Edit: May 14, 2019, 06:24 am by jpedrego
Something is definitely wrong with this DUE...

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...


ard_newbie

#8
May 14, 2019, 07:50 am Last Edit: May 14, 2019, 07:53 am by ard_newbie
Let's check a few details.

When you upload a sketch:
- 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 ?

jpedrego


When you upload a sketch:
- 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



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???

ard_newbie


Another test:

Select the programming port in Tools>board, hook the cable to the programming port

Upload the sketch pert provided in #reply 3 thru the programming port

detach the cable, hook the cable now to the Native USB port

Open another IDE and select the Native USB port in Tools>board

Select the correct COM port in Tools>Port  (COMx(Native USB Port)

push the reset button

Does the uploaded sketch run ?

jpedrego

Did as asked: yes the sketch runs.

It is this normal behavior for the DUE?

ard_newbie

#12
May 14, 2019, 08:50 am Last Edit: May 14, 2019, 08:53 am by ard_newbie
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.

Any other behavior is abnormal.

pert

It is this normal behavior for the DUE?
I just uploaded my test serial code to a Due via the Native USB port and it works as expected for me.

jpedrego

Dear all,

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:

Code: [Select]

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):
Code: [Select]

%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')



I got many things from
http://nicecircuits.com/playing-with-analog-to-digital-converter-on-arduino-due/
https://gist.github.com/pklaus/5921022

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.

Thank anyway for your help.

Go Up