how to set preference to Specify Arduino board?
Show older comments
trouble following these instruction,
b) Specify Arduino board (Duemilanove, Uno, Mega, etc.)
>> arduino.Prefs.setBoard % see list of board options
>> arduino.Prefs.setBoard('uno') % choose a specific board
my matlab comand errors:
>> arduino.Prefs.setBoard ??? Reference to non-existent element of a cell array.
Error in ==> Prefs>Prefs.parseBoardsFile at 227 lhs = parsedLines{i}{1}{1}; % can be of the form xx.yy.zz
Error in ==> Prefs>Prefs.setBoard at 66 boards = arduino.Prefs.parseBoardsFile(boardsFile);
>> arduino.Prefs.setBoard('Mega') ??? Reference to non-existent element of a cell array.
Error in ==> Prefs>Prefs.parseBoardsFile at 227 lhs = parsedLines{i}{1}{1}; % can be of the form xx.yy.zz
Error in ==> Prefs>Prefs.setBoard at 66 boards = arduino.Prefs.parseBoardsFile(boardsFile);
1 Comment
Kaustubha Govind
on 9 Oct 2012
I don't have experience with this product, but looking at the code for arduino.Prefs, it looks like it is having trouble parsing the boards.txt file, locatable via the MATLAB command:
fullfile(arduino.Prefs.getArduinoPath(), 'hardware', 'arduino', 'boards.txt')
Perhaps you can either fix the regexp command in arduino.Prefs.parseBoardsFile, or fix your boards.txt file to conform to what the regexp command expects.
Answers (1)
Peter
on 23 Sep 2013
This problem seems to repeat across the forums with no definitive answer. I had exactly the same issue last night and this was my solution - to help those in a similar situation.
The issue concerns the parsing of the boards.txt file by a function in Prefs.h
I put a few lines of debug code into Prefs.h to send the output of each stage of parsing to the console. The parsing is done in two stages in the function parseBoardsFile(filename) at line 214.
The first by:
txt = textscan(fid,'%s','commentstyle','#','delimiter','\n','multipledelimsasone',true);
And the second:
parsedLines = regexp(rawLines,'^([^=]+)=([^$]+)$','tokens');
The error occurs at stage one but the program falls over at stage two because the regexp is not being fed what it expects (programmer expected).
The boards.txt file starts:
# See: http://code.google.com/p/arduino/wiki/Platforms
##############################################################
uno.name=Arduino Uno
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.speed=115200
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
The textscan at the first stage should strip out comment lines starting with # but for some reason it misses the first multiple # line. The output at stage one is something like:
##############################################################
uno.name=Arduino Uno
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.speed=115200
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
but it should be:
uno.name=Arduino Uno
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.speed=115200
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
Therefore the first output string of txt{1} is:
##############################################################
And not:
uno.name=Arduino Uno
Therefore:
parsedLines = regexp(rawLines,'^([^=]+)=([^$]+)$','tokens');
Does not create the expected parsedLines array and it falls over on line 227:
lhs = parsedLines{i}{1}{1}; % can be of the form xx.yy.zz
The ANSWER:
I don’t know why the textscan doesn't remove the first multiple hash line because, to me, it looks like it should.
However removing the first line reference to the wiki
# See: http://code.google.com/p/arduino/wiki/Platforms
Solves the issue as textscan gets it right from then on.
Therefore change your boards.txt file to start with the first multi hash line at line 1:
##############################################################
uno.name=Arduino Uno
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.speed=115200
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
uno.bootloader.path=optiboot
To do that you will probably have to change your access permissions for the containing folder to write/modify as it’s likely set to read only.
And then it works. Hope that wraps that one up for everyone. Now on to the next error message!
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!