0

I have a project that requires a Raspberry Pi 3 to read 4 USB inputs coming from 4 microcontrollers (SAMD21G mini breakout boards in particular). They are connected directly via USB. Raspberry Pi 3 is running Windows IOT core.

I have used microsoft's Serial Sample app with success on reading up to 3 inputs simultaneously.

The problem is everytime i try 4 USB inputs, the raspberry pi hangs and disconnects from remote debugging, then I have to restart the Pi so i can do remote debugging again.

Below is a snippet of the code where the problem occurs.

everything stops at the line: "serialPort4 = await SerialDevice.FromIdAsync(entry4.Id);"

I've already tried the program on a PC and it works fine. Has anyone encountered this issue? any help would be appreciated :)

   private async void comPortInput_Click_1(object sender, RoutedEventArgs e)
    {
        var selection = ConnectDevices.SelectedItems;

        if (selection.Count <= 0)
        {
            status.Text = "Select a device and connect";
            return;
        }



        DeviceInformation entry1 = (DeviceInformation)selection[0];
        DeviceInformation entry2 = (DeviceInformation)selection[1];
        DeviceInformation entry3 = (DeviceInformation)selection[2];
        DeviceInformation entry4 = (DeviceInformation)selection[3];

        try
        {

            serialPort1 = await SerialDevice.FromIdAsync(entry1.Id);
            serialPort2 = await SerialDevice.FromIdAsync(entry2.Id);
            serialPort3 = await SerialDevice.FromIdAsync(entry3.Id);
            serialPort4 = await SerialDevice.FromIdAsync(entry4.Id);

            if (serialPort1 == null || serialPort2 == null || serialPort3 == null || serialPort4 == null)
            {
                status.Text = "null";
                return;                  
            }


            // Disable the 'Connect' button 
            comPortInput.IsEnabled = false;

            // Configure serial settings
            serialPort1.WriteTimeout = TimeSpan.FromMilliseconds(3);
            serialPort1.ReadTimeout = TimeSpan.FromMilliseconds(3);
            serialPort1.BaudRate =9600;     //57600
            serialPort1.Parity = SerialParity.None;
            serialPort1.StopBits = SerialStopBitCount.One;
            serialPort1.DataBits = 8;
            serialPort1.Handshake = SerialHandshake.None;


            serialPort2.WriteTimeout = TimeSpan.FromMilliseconds(3);
            serialPort2.ReadTimeout = TimeSpan.FromMilliseconds(3);
            serialPort2.BaudRate = 9600;     //57600
            serialPort2.Parity = SerialParity.None;
            serialPort2.StopBits = SerialStopBitCount.One;
            serialPort2.DataBits = 8;
            serialPort2.Handshake = SerialHandshake.None;


            serialPort3.WriteTimeout = TimeSpan.FromMilliseconds(3);
            serialPort3.ReadTimeout = TimeSpan.FromMilliseconds(3);
            serialPort3.BaudRate = 9600;     //57600
            serialPort3.Parity = SerialParity.None;
            serialPort3.StopBits = SerialStopBitCount.One;
            serialPort3.DataBits = 8;
            serialPort3.Handshake = SerialHandshake.None;


            serialPort4.WriteTimeout = TimeSpan.FromMilliseconds(3);
            serialPort4.ReadTimeout = TimeSpan.FromMilliseconds(3);
            serialPort4.BaudRate = 9600;     //57600
            serialPort4.Parity = SerialParity.None;
            serialPort4.StopBits = SerialStopBitCount.One;
            serialPort4.DataBits = 8;
            serialPort4.Handshake = SerialHandshake.None;


            // Create cancellation token object to close I/O operations when closing the device
            ReadCancellationTokenSource = new CancellationTokenSource();
            if (serialPort1 != null || serialPort2 != null || serialPort3 != null || serialPort4 != null) //|| serialPort4 != null
            {
                // Create the DataWriter object and attach to OutputStream
                dataWriteObject1 = new DataWriter(serialPort1.OutputStream);
                dataWriteObject2 = new DataWriter(serialPort2.OutputStream);
                dataWriteObject3 = new DataWriter(serialPort3.OutputStream);
                dataWriteObject4 = new DataWriter(serialPort4.OutputStream);
                //Launch the WriteAsync task to perform the write
                await WriteAsync();
            }
            else
            {
                status.Text = "Select a device and connect";
            }

            Listen();
        }
        catch (Exception ex)
        {
            status.Text = ex.Message;
            comPortInput.IsEnabled = true;
            //sendTextButton.IsEnabled = false;
        }
    }
marionR
  • 1
  • 1
  • Can you get a COM port when connecting SAMD21G mini breakout board with PC? What's the version of your Windows IoT core? – Rita Han May 22 '17 at 05:40
  • Hello Rita Han, yes I am able to get a COM port when connecting the breakout board with the PC. I dont have the raspberry pi right now, ill be able to tell you the version tomorrow, thanks. – marionR May 22 '17 at 17:14
  • Hello, the OS version of the IoT core is 10.0.16193.1001 – marionR May 23 '17 at 03:00
  • I can have four USB inputs(not SAMD21G) worked. Have you tried to replace some of SAMD21G devices using other, something like [USB to serial device](http://www.ftdichip.com/Products/Cables/USBRS232.htm)? – Rita Han May 23 '17 at 07:38
  • what did you use as your USB inputs? we're trying to avoid using a USB to TTL cable because it is additional hardware. – marionR May 23 '17 at 09:38
  • Not let you use additional hardware, just for test purpose to check if the problem is residing in SAMD21G side or not. I use some kinds device but didn't reproduce your issue. – Rita Han May 23 '17 at 09:44
  • Ok ill look if we have other USB input i can use. ill let you know how it turns out. – marionR May 23 '17 at 11:00
  • so we have a usb-ttl cable lying around and i tried connecting tx, rx, and gnd to one of the SAMD21G boards, also this SAMD21G is powered separately (not powered by the RasPi USB port). The RasPi was able to read 4 inputs but it was very slow, i'll still do some checking, but atleast something worked! – marionR May 23 '17 at 11:54
  • Have you tried higher baud rate? – Rita Han May 24 '17 at 01:41
  • yes, the baudrate is now 115200, i'm now able to read 4 inputs but it stops a little bit for a few seconds, then it continues, then it stops again for a few seconds then it continues and so on. – marionR May 24 '17 at 04:54
  • It's working now, 2 SAMD21G's are connnected via USB-Serial module, and the other 2 SAMD21G's are connected DIRECTLY via USB. But i still dont know why connecting 4 SAMD21G's DIRECTLY to USB doesn't work. Is it because the device is not supported by IoT core? – marionR May 24 '17 at 09:43
  • You have _2 SAMD21G's connected DIRECTLY via USB_ worked, isn't it? So, the device is actually supported by Windows IoT core. As for 4 SAMD21G's DIRECTLY to USB, **maybe** there are not enough current supply? It is needed to do more research. – Rita Han May 25 '17 at 01:45
  • I went back to connecting 4 SAMD21G's directly and measure voltage and current going to RPi: (with no USB connected: 0.3amps) (with 4 SAMD21G's connected: 0.4 - 0.44 amps) (when the app runs: 0.4 - 0.44 amps) the voltage was steady at 4.99 V all through out. – marionR May 25 '17 at 04:21
  • I also measured current going in RasPi with 2 directly via USB and 2 connected through USB-serial device, and i got 0.5 to 0.56 Amps which is higher current consumption than connecting the 4 directly by USB so this means there is enough current supply. – marionR May 25 '17 at 05:15
  • I mean the power supplied to SAMD21G from Raspberry. If possible you can use USB hub or other to supply power to all SAMD21Gs but not raspberry pi. You can reference [this](https://raspberrypi.stackexchange.com/questions/340/how-much-power-can-be-provided-through-usb). – Rita Han May 25 '17 at 05:49
  • I tried making a test USB cable(i cut the cable so i can tap a multimeter on it) so i can measure current going from RasPi USB to the SAMD21G. I noted down the current of each when connected to my PC while running the app, and then did the same when connected to the RasPi. With 4 USB inputs to the RasPi each SAMD21G draws about "25mA to 33mA" which is safe below the 100mA limit described in the link you provided. I think we can now say it's not a power issue. – marionR May 25 '17 at 09:12

0 Answers0