How can I force an Arduino Leonardo to reset with AVRDUDE? - arduino

I want to compile and transfer an Arduino program by myself on a Leonardo board.
Everything works great with the Arduino official IDE. I have enabled verbose mode for compiling and bytecode transfer.
I can see each command line.
I want to understand each line.
Everything is good except last step: transfer with AVRDUDE. If I type exactly the same command, I get an error:
.avrdude: butterfly_recv(): programmer is not responding
This error is not present if I upload code with the Arduino IDE.
I can see a difference - the Arduino IDE displays this line before the AVRDUDE call:
Forcing reset using 1200 bps open/close on port /dev/cu.usbmodem1431
How can I make this reset by command line?

I had the same issue on macOS, and I came up with the following Bash script:
# Find the Arduino port
ARDUINO_UPLOAD_PORT="$(find /dev/cu.usbmodem* | head -n 1)"
# Reset the Arduino
stty -f "${ARDUINO_UPLOAD_PORT}" 1200
# Wait for it...
while :; do
sleep 0.5
[ -c "${ARDUINO_UPLOAD_PORT}" ] && break
done
# ...upload!
avrdude "${OPTIONS[#]}"
The while loop is the trick! It's going to proceed as soon as the Arduino port is back online.
This is part of a Makefile I wrote for the project Sesame.

For uploading from Windows, I made a bat file wrapper for AVRDUDE.
It identifies the Leonardo COM port with WMI, resets this COM port to 1200 baud with the MODE command, identifies the bootloader COM port and invokes AVRDUDE.
The firmware is supposed to be placed in firmware.hex, but it can be changed to be supplied from the command line.
Code is in a GitHub repository, Arduino Leonardo Uploader
Or below:
#echo off
setlocal
for /f "tokens=1* delims==" %%I in ('wmic path win32_pnpentity get caption /format:list ^| find "SparkFun Pro Micro"') do (
call :resetCOM "%%~J"
)
:continue
:: wmic /format:list strips trailing spaces (at least for path win32_pnpentity)
for /f "tokens=1* delims==" %%I in ('wmic path win32_pnpentity get caption /format:list ^| find "Arduino Leonardo bootloader"') do (
call :setCOM "%%~J"
)
:: end main batch
goto :EOF
:resetCOM <WMIC_output_line>
:: sets _COM#=line
setlocal
set "str=%~1"
set "num=%str:*(COM=%"
set "num=%num:)=%"
set port=COM%num%
echo %port%
mode %port%: BAUD=1200 parity=N data=8 stop=1
goto :continue
:setCOM <WMIC_output_line>
:: sets _COM#=line
setlocal
set "str=%~1"
set "num=%str:*(COM=%"
set "num=%num:)=%"
set port=COM%num%
echo %port%
goto :flash
:flash
avrdude -v -C./avrdude.conf -patmega32u4 -cavr109 -P%port% -b57600 -D -V -Uflash:w:./firmware.hex:i

I had the same problem. I've tried opening and closing the ACM0 port with a Python script at 1200 baud, as someone already mentioned. It didn't work for me. Then I have received half-advice to try toggling RTS/DTS and that will make autoreset. So in the end I found the solution (at least for me) on Linux Mint 18.2 (Sonya):
#! /usr/bin/python
import sys
import serial
com = serial.Serial(sys.argv[1], 1200)
com.dtr=False
com.close()
python ./reset.py "/dev/ttyACM0"
dmesg shows me:
[21850.047120] cdc_acm 1-1:1.0: ttyACM0: USB ACM device
[22093.700327] usb 1-1: USB disconnect, device number 53
[22094.034133] usb 1-1: new full-speed USB device number 54 using xhci_hcd
[22094.175377] usb 1-1: New USB device found, idVendor=2341, idProduct=0036
[22094.175381] usb 1-1: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[22094.175384] usb 1-1: Product: Arduino Leonardo
[22094.175387] usb 1-1: Manufacturer: Arduino LLC
[22094.175964] cdc_acm 1-1:1.0: ttyACM0: USB ACM device

On Windows, in a command prompt, the same solution, slightly different batch file:
It determines the bootloader COM port as well. Note that just only the Leonardo to be flashed should be connected!
#echo off
echo Upgrade procedure starting.
if %1.==. goto error
set hexfile=%1
set comportA=NONE
set comportB=NONE
if not exist %hexfile% goto error
for /f "usebackq" %%B in (`wmic path Win32_SerialPort Where "Caption LIKE '%%Leonardo%%'" Get DeviceID ^| FIND "COM"`) do set comportA=%%B
if %comportA%==NONE goto nodevice
echo COM port for Arduino device is detected as %comportA%.
echo Reset Arduino into bootloader
mode %comportA%: baud=12 > nul
timeout 2 > nul
for /f "usebackq" %%B in (`wmic path Win32_SerialPort Where "Caption LIKE '%%Leonardo%%'" Get DeviceID ^| FIND "COM"`) do set comportB=%%B
if %comportB%==NONE goto nobldevice
echo COM port for Arduino bootloader device is detected as %comportB%.
echo.
echo Starting AVR Downloader/UploaDEr.....
avrdude -pm32u4 -cavr109 -D -P%comportB% -b57600 -Uflash:w:%hexfile%
goto upgradedone
:nodevice
echo No matching module found, you should connect the module you want to upgrade.
goto end
:nobldevice
echo Reset into bootloader failed, please try again...
goto end
:error
Echo Missing parameter or file, you should provide the full filename of an existing .hex file you want to use.
goto end
:upgradedone
echo.
echo Upgrade done!
:end

I use this for Nano-every:
I think the essential elements are:
configure appropriate com port at 1200 baud with DTR = ON
Turn DTR off.
Flash device with correct version of avrdude and avrdude.config. My version came with the installation of my Nano-every device.
For other boards, it might be different. Lines 1, 2 reset the port and I think this is independent of the board, but change the port number!
c:\windows\system32\mode.com com6: baud=1200 dtr=on
c:\windows\system32\mode.com com6: dtr=off
C:\Users\Ludo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\Ludo\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega4809 -cjtag2updi -PCOM6 -b115200 -e -D -Uflash:w:C:\Users\Ludo\AppData\Local\Temp\arduino_build_385557/sketch_dec11a.ino.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x00:m {upload.extra_files}

Well, you pretty much wrote the answer yourself.
You need to open a serial connection at 1200 baud to the Arduino and then close the connection. The Arduino will then boot into SAM-BA, and reset itself, and is now ready for a new program.

I had the same problem with arduino leonardo.
I want to share my solution for people wanting to solve this problem using Qt.
Here is solution ready to be copy and paste, also taking care of timeout:
#include <QtCore/QString>
#include <QtCore/QDebug>
#include <QtCore/QThread>
#include <QtCore/QElapsedTimer>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
bool forceResetComPort(const QString& portName)
{
QSerialPort serial;
serial.setPortName(portName);
serial.setBaudRate(1200);
qDebug() << "Forcing reset using 1200bps open/close on port ") << portName;
if(!serial.open(QIODevice::ReadWrite))
return false;
// This seems optional
serial.setDataTerminalReady(false);
qDebug() << "Waiting for the new upload port...";
QElapsedTimer timeoutWatcher;
qint64 timeoutMs = 10000;
bool isPortPresent = true;
const auto fetchIsPortPresent = [&]() -> bool
{
const auto ports = QSerialPortInfo::availablePorts();
for(const auto& info : ports)
{
if(info.portName() == serial.portName())
return true;
}
return false;
};
timeoutWatcher.start();
// Wait for port to disconnect
while(isPortPresent && !timeoutWatcher.hasExpired(timeoutMs))
{
isPortPresent = fetchIsPortPresent();
if(isPortPresent)
QThread::msleep(1);
}
serial.close();
// Wait for port to reconnect
while(!isPortPresent && !timeoutWatcher.hasExpired(timeoutMs))
{
isPortPresent = fetchIsPortPresent();
if(!isPortPresent)
QThread::msleep(1);
}
return !timeoutWatcher.hasExpired(timeoutMs);
}
It is all about timing. I really needed to wait for the serial port to disconnect to close serial.
Closing too fast didn't have any effect.
Closing too slow, the usb serial was reconnecting but with a different port name. (For example /dev/ttyACM0 to /dev/ttyACM1).
It's important to wait for the port to reconnect in my case because I call avrdude in QProcess after.
Here is dmesg:
[ 8566.623621] cdc_acm 1-8:1.0: failed to set dtr/rts
[ 8566.979697] usb 1-8: new full-speed USB device number 21 using xhci_hcd
[ 8567.133193] usb 1-8: New USB device found, idVendor=2341, idProduct=0036, bcdDevice= 0.01
[ 8567.133197] usb 1-8: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[ 8567.133199] usb 1-8: Product: Arduino Leonardo
[ 8567.133200] usb 1-8: Manufacturer: Arduino LLC
[ 8567.134820] cdc_acm 1-8:1.0: ttyACM0: USB ACM device

Related

Unable to remote debug gdbserver over serial port

I'm trying to remote debug using gdbserver.
I connect my target device to my PC through USB port using this command to open terminal controlling my device :
minicom -D "/dev/ttyUSB0".
Now on my target device, I need to run gdbserver with this cmd:
gdbserver /dev/my_USB_serial_port my_Program.
However, I can't find ttyUSB0, all I got ís a bunch of ttyx(with x is a number) as below:
~ # /dev/tty
tty tty14 tty20 tty27 tty33 tty4 tty46 tty52 tty59 tty8
tty0 tty15 tty21 tty28 tty34 tty40 tty47 tty53 tty6 tty9
tty1 tty16 tty22 tty29 tty35 tty41 tty48 tty54 tty60 ttyS0
tty10 tty17 tty23 tty3 tty36 tty42 tty49 tty55 tty61 ttyS1
tty11 tty18 tty24 tty30 tty37 tty43 tty5 tty56 tty62
tty12 tty19 tty25 tty31 tty38 tty44 tty50 tty57 tty63
tty13 tty2 tty26 tty32 tty39 tty45 tty51 tty58 tty7
How could I find which one is the correct serial port of my USB port ?
Update 1: As Employed Russian mentioned in the answer, I got confused about the USB port but I still couldn't connect to gdbserver using his command.
However, I can't find ttyUSB0
You are confused -- of course you will not find ttyUSB0 on the target -- the target doesn't have anything plugged into its USB port.
On the target, you want to run gdbserver - my_Program &, then disconnect minicom, and finally use gdb and target remote /dev/ttyUSB0 on the host.
Make sure getty isn't running on the same serial port as gdbserver on the target.
If you've got an interactive shell with minicom, check the serial port (usually ttyS0) on the target that's connected to it. If it's ttyS0, you start gdbserver on some other port, and connect another FTDI cable from that port to a second USB port on your host.

How to send boot files over uart

I have a beaglebone black board. A host with 64 bit ubuntu14.04
I wanted to transfer uImage file over uart to beaglebone.
So I stopped at u-boot and type
U-Boot# loadb
## Ready for binary (kermit) download to 0x80200000 at 115200 bps...
Now it is waiting for the file. What I have to do in order to send the uImage from pc to board.
After the loadb command prints "Ready for binary download", exit from the terminal(minicom, putty etc). Note down the serial device (eg: /dev/ttyUSB0). Install kermit or its variants (eg: gkermit and ckermit are available in Ubuntu).
Assuming that /dev/ttyUSB0 is your serial device, baudrate is 115200, and no flow control is used, provide the following parameters to kermit
$kermit
kermit> set port /dev/ttyUSB0
kermit> set speed 115200
kermit> set carrier-watch off
kermit> set flow-control none
Now issue the command send , to send the file over serial line:
kermit> send filename
After the file transfer is successful, exit from kermit (use exit command), and re-open minicom. Now you can issue further commands.
NOTE : You can explicitly specify a load address to loadb. If not specified, U-boot takes load address from environment variables.
NOTE-2 : Some terminal programs have built-in facility to send files over serial line using protocols like xmodem or kermit.

Unable to program NodeMCU

This question is related to this, Cannot program ESP8266, but different settings.
I have a NodeMCU devkit v1, its comercial name is NodeMCU v2. I tried different setting to connect the devkit.
First the devkit has a usb-serial bridge (CP2102) and voltage adapter from 5v (USB) to 3.3v. So I connect the devkit with the machine via USB. The driver is installed correctly, and I can see the com, it is COM3.
After turning on the NodeMCU I can see a Wifi AI-THINKER-adfe21.
Then I tried with the nodemcu-flasher - WINDOWS.
Without any button or pin to ground. I press Flash in the flasher and stay Waiting MAC and the log says Begin Find ESP8266 as the question I told in the begin and the ESP's led (blue led) blinks.
Holding FLASH, press RESET, release FLASH. Still the same like 1.
Wire D3 (GPIO0) to GND. Same result
With ESPtool - LINUX - Trying these commands
python2 esptool.py --port /dev/ttyUSB0 read_mac
python2 esptool.py --port /dev/ttyUSB0 write_flash 0x00000 firmware.bin
Without any button or pin to ground. The output for the commands was Connecting... A fatal error occurred: Failed to connect to ESP8266
Holding FLASH, press RESET, release FLASH. Same
Wire D3 (GPIO0) to GND. Same result.
Via Arduino IDE, I installed the ESP8266 board and selected NodeMCU 1.0. The result to try upload some code -> warning: espcomm_sync failed error: espcomm_open failed
I tryed to connect the NodeMCU without the USB. Using an Arduino UNO, connecting like following... And I'm getting the same errors.
UNO | NodeMCU
5v -> Vin
GND -> GND
Rx -> Tx
Tx -> Rx
The last test I made, it is with Putty or Arduino SerialMonitor connect to the COM3 or /dev/ttyUSB0 and turning on the NodeMCU. I should see some characters or garbage if it in different baud rate. But I got nothing, the terminal is blank. I restart the NodeMCU, put it in Flash mode. No response.
Are there some solution, tip or trick to make it programmable?
PS: I know the NodeMCU is in Flash mode because its wifi disappear.
EDIT:
I discovered something.
I just connected the NodeMcu with a mobile charger and connect the D0 to Serial ground and D3 to Serial Rx. On the putty with 115200 Baudrate, I'm able to get the following code on reset.
node : sta(mac address) + softAP(mac address)
add if0
add if1
dhcp server start:(ip:192.168.4.1, mask:255.255.255.0,gw:192.168.4.1)
bcn 100
I have been working with both the node-mcu flasher and the esptool.
First in the esptool yo should use more parameter in the call. Use something like this
python esptool.py -p SERIAL_PORT_NAME --baud 9600 write_flash --flash_size=8m 0 firmware-combined.bin
Be careful with the baudrate, i always use 9600.
If you prefer using the windows program you should only connect the ESP8266 through usb and dont connect any other pin. If it still gives you problems you should check that u have installed the com ports.
Good Luck
if you are using esptool (either in Linux or windows), you should include -fm and -fs inside the esptool command. There will be no response if you did not include those 2 parameter even though it show successfully upload. you can refer the detail in this youtube tutorial or its description for flashing firmware in nodemcu V2 or v1.0.
esptool.py --port [serial-port-of-ESP8266] write_flash -fm [mode] -fs [size] 0x00000 [nodemcu-firmware].bin
Tutorial on how to flash firmware using esptool(windows):
https://www.youtube.com/watch?v=MHrm7axsImI
cheers!
Maybe you can try this setting.
$sudo esptool.py -p /dev/ttyUSB0 --baud 115200 write_flash -fs 16m -fm qio -ff 0x00000 firmware.bin

Can't send data to Xively through Arduino Wi-Fi Shield, sending just one stream

I'm doing a project involving uploading data wirelessly, from an analog sensor. In this case it is a light sensor.
I am using an Arduino Uno R2, and an official Arduino Wi-Fi Shield. Below is my code:
#include <SPI.h>
#include <WiFi.h>
#include <HttpClient.h>
#include <Xively.h>
char ssid[] = "Bradley's MacBook Pro"; // your network SSID (name)
int status = WL_IDLE_STATUS;
// Your Xively key to let you upload data
char xivelyKey[] = "SOP7lASYJVcRecV98zlHosDc9nLIAXqnDnIxRnXAmNeKorIk";
// Analog pin which we monitor (0 and 1 are used by the Ethernet shield)
int sensorPin = 2;
// Define the strings for our datastream IDs
char sensorId[] = "light";
XivelyDatastream datastreams[] = {
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(1125419529, datastreams, 1 /* number of datastreams */);
WiFiClient client;
XivelyClient xivelyclient(client);
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Starting single datastream upload to Xively...");
Serial.println();
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
}
void loop() {
int sensorValue = analogRead(sensorPin);
datastreams[0].setFloat(sensorValue);
Serial.print("Read sensor value ");
Serial.println(datastreams[0].getFloat());
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println();
delay(15000);
}
However unfortunately every time I get this back in serial:
Attempting to connect to SSID: Bradley's MacBook Pro
Connected to wifi
SSID: Bradley's MacBook Pro
IP Address: 10.0.2.3
signal strength (RSSI):-20 dBm
Read sensor value 1023.00
Uploading it to Xively
xivelyclient.put returned -1
Read sensor value 1023.00
Uploading it to Xively
xivelyclient.put returned -1
Read sensor value 684.00
Uploading it to Xively
xivelyclient.put returned -1
Read sensor value 684.00
Uploading it to Xively
xivelyclient.put returned -1
Read sensor value 684.00
Uploading it to Xively
No Socket available
xivelyclient.put returned -1
Read sensor value 684.00
Uploading it to Xively
No Socket available
xivelyclient.put returned -1
I noticed that after a few attempted it started to say No Socket available.
Does anyone have any clues as to where I've gone wrong?
I have resolved this problem. The issue is that I was using Arduino IDE 1.0.5 and there is a bug in that which prevents Wi-Fi communication. I have now changed to using an earlier IDE 1.0.2 and everything is running perfectly.
Even if you change IDE version to 1.0.2 , for few months it worked fine. If this problem occurs again, consider upgrading Wifi Shield Firmware . Latest package availble in Arduino site.It solved the error
Steps to follow for ugrading:
1. Download and install Flip from here. http://www.atmel.com/tools/FLIP.aspx You don't need to use or run the Flip program. There is a sub-program in the download you will need to use later. You will get to this sub-program (batchslip.exe) using a DOS command prompt. There is also a driver for the chip on the WiFi Shield (AT32UC3A or AT32UC3A DFU) that you will need.
If you recently installed a version of Arduino onto your computer, the software you need to update the WiFi Shield is in the Arduino directory structure. I know this to be true for me when I recently installed Arduino Version 1.0.5. (You might need to install a current version).
Connect your WiFI Shield to the Uno board. Put the jumper across both pins on 'DFU Programming Jumper'. Shown on 4th picture of the WiFi Shield on this page: ? http://arduino.cc/en/Main/ArduinoWiFiShield
To find the picture of the jumper, look for the words and arrow pointing to the board " DFU programming jumper (only used for updating shield firmware, leave unconnected for typical use)".
Connect power to your Arduino. Then connect a mini USB to the WiFi shield (not a micro-USB) and your computer.
Hopefully your Windows Device manager will show AT32UC3A DFU under "Other Devices". You may have to play with plugging/ unplugging power to Arduino and also the WiFI Shield's USB port connected to your computer. One time I had luck by not powering the Arduino and only plugging in the USB mini between computer and the WiFi Shield.
Right-Click on the device in 'Device Manager' and select "Update Driver" . I chose to install from my computer and directed the Device Installer application to Install from... C:\Program Files (x86)\Atmel\Flip 3.4.7 . I had an option to click "Include Subdirectories'. Sorry, I am not certain what sub-folder the driver might actually be in. When this step is complete, The AT32UC3A DFUshould be properly listed in Device Manager under "Atmel USB Devices".
Open a command prompt and navigate to the directory where "batchslip.exe" was installed by Flip. For me it was C:\Program Files (x86)\Atmel\Flip 3.4.7\bin ...but it depends where the Atmel software is installed and what version you download.
Once you are in the directory ( C:\Program Files (x86)\Atmel\Flip 3.4.7\bin) , you will need to run two commands. You will need to determine where you initially installed your Arduino software. I installed mine in C:\Arduino instead of the recommended lengthy folder suggested ( * something like C:\Arduino 1.0.5.) .. Therefore you might need to adjust the directory structure in the two commands I have listed below.
I suggest Cut and paste the first command from below, then make it match your * Arduino folder name. You may have to dump the following command in to a notepad or something to make sure there are no line breaks. Make the path as small as possible. Don't paste Arduino folder in program files while upgrading,because if path has Program Files (x86) ,spaces in between words will create un necessary error like : missing arguments
"
c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>batchisp.exe -device AT32UC3A1256 -hardware usb -operation erase f memory flash blankcheck loadbuffer c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifi_dnld.elf program verify start reset 0
"
Here is what you should see on the command line..........
Running batchisp 1.2.5 on Sat May 10 21:16:01 2014
AT32UC3A1256 - USB - USB/DFU
Device selection....................... PASS
Hardware selection..................... PASS
Opening port........................... PASS
Reading Bootloader version............. PASS 1.0.2
Erasing................................ PASS
Selecting FLASH........................ PASS
Blank checking......................... PASS 0x00000 0x3ffff
Parsing ELF file....................... PASS c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifi_dnld.elf
WARNING: The user program and the bootloader overlap!
Programming memory..................... PASS 0x00000 0x2902b
Verifying memory....................... PASS 0x00000 0x2902b
Starting Application................... PASS RESET 0
Summary: Total 11 Passed 11 Failed 0
c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>
Now to update the second piece
Cut and paste the command from below. You may have to dump it in to a notepad or something to make sure there are no line breaks.
"
c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>batchisp.exe -device AT32UC3A1256 -hardware usb -operation erase f memory flash blankcheck loadbuffer c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifiHD.elf program verify start reset 0
"
Press Enter
Here is what will happen on your screen..
Running batchisp 1.2.5 on Sat May 10 21:34:04 2014
AT32UC3A1256 - USB - USB/DFU
Device selection....................... PASS
Hardware selection..................... PASS
Opening port........................... PASS
Reading Bootloader version............. PASS 1.0.2
Erasing................................ PASS
Selecting FLASH........................ PASS
Blank checking......................... PASS 0x00000 0x3ffff
Parsing ELF file....................... PASS c:\Arduino\hardware\arduino\firmwares\wifishield\binary\wifiHD.elf
WARNING: The user program and the bootloader overlap!
Programming memory..................... PASS 0x00000 0x3fe2b
Verifying memory....................... PASS 0x00000 0x3fe2b
Starting Application................... PASS RESET 0
Summary: Total 11 Passed 11 Failed 0
c:\Program Files (x86)\Atmel\Flip 3.4.7\bin>
Remove the Jumper from the WiFi Card. Remove the Min USB.
Verify Wifi shield with any sketch.
This method really solved the No Socket available issue.

How to make Scilab open a serial communication with /dev/ttyACM0 USB port in Linux (Ubuntu)

I'm trying to open a serial communication between Scilab and Arduino. However, Arduino is always recognized by Linux Ubuntu in the /dev/tty**ACM0** port. When I write h=openserial(1,"9600,n,8,1) in Scilab I know that I'm saying to it, to open a serial comunication to COM1 or /dev/tty**S0** in Linux.
But, for example, if I use h=openserial(N,"9600,n,8,1), assuming N=port number, I will always have COMN, in Windows and /dev/tty**S**(N-1) in Linux.
How do I open a serial comunication through /dev/tty**ACM0** port in Scilab for Linux?
Looking at the openserial.sci from the Serial Communication Toolbox for Scilab repo,
function h=openserial(p,smode,translation,handshake,xchar,timeout)
//port name
if ~exists("p","local") then p=1; end
if type(p)==1 | type(p)==8 then
if p<=0 then error("port number must be greater than zero"); end
if getos() == "Windows" then
port="COM"+string(p)+":"
else
port="/dev/ttyS"+string(p-1)
end
elseif type(p)==10
port=p
else
error("port to open must be either a number or a string")
end
The port is always set to /dev/ttyS<PORT_NUMBER>. So in your local toolbox files, you could try editing the following lines in openserial.sci to something like this:
function h=openserial(p,smode,translation,handshake,xchar,timeout)
//port name
if ~exists("p","local") then p=1; end
if type(p)==1 | type(p)==8 then
if p<=0 then error("port number must be greater than zero"); end
if getos() == "Windows" then
port="COM"+string(p)+":"
else
port="/dev/ttyS"+string(p-1)
end
elseif type(p)==10
port=p
elseif type(p)=="ACM0"
port="/dev/ttyACM0"
else
error("port to open must be either a number or a string")
end
and then call openserial as follows:
h=openserial("ACM0","9600,n,8,1)
Also make sure that /dev/ttyACM0 is the correct device node. This is a sample output from ls -l, that you can run to confirm:
$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 188, 0 Mar 12 18:16 /dev/ttyACM0
If you're getting errors opening the serial port as a regular user, you might add yourself to the correct group. Based on the above example, the group name is dialout on my openSUSE distro. It might be different on yours, so substitute that group name in the following command:
sudo usermod -a -G dialout <USER_NAME>
Just type:
h = openserial("/dev/ttyACM0", "9600, n, 8, 1");
and you are done.
keep simple, STRINGS its a valid option to port, so as Luis post:
"...Just type:
h = openserial("/dev/ttyACM0", "9600, n, 8, 1");
and you are done..."
As an example, supouse your arduino its on serial port "/dev/ttyACM0" type on Scilab:
n=300 // plot 300 data points from serial port "/dev/ttyACM0"
h=openserial("/dev/ttySACM0","9600,n,8,1")
i=1;
while i<=n
data(i) = strtod(readserial(h)); // char to number
plot(i,data(i),'b-o'); // real time plot
drawnow(); // show data
i=i+1;
end

Resources