Replace this file in TurtleArt.activity/plugins/arduino/ This file not have any calidation, if something is wrong, in the log will appears that.
From: [email protected] Date: Thu, 4 Oct 2012 23:36:29 -0400 Subject: Re: [IAEP] Arduino and XO-1 To: [email protected] CC: [email protected]; [email protected]; [email protected] Alan, I have uploaded the newest version of Firmata to the Arduino board, and still get the first error in your list.Any thoughts about what I should do next? Thanks. Gerald On Thu, Oct 4, 2012 at 11:22 PM, Alan Jhonn Aguiar Schwyn <[email protected]> wrote: Hi, The Arduino plugin have some checks. This checks are: 'ERROR: Check the Arduino and the number of port.''ERROR: Value must be a number from 0 to 255.' 'ERROR: Value must be either HIGH or LOW.''ERROR: The mode must be either INPUT, OUTPUT, PWM or SERVO.' The Arduino board needs have the Firmata firmware [1]. The checks are catched with try/excepts that not allows see what is wrong.I can make a version without it to test.. Regards! Alan [1] http://firmata.org/wiki/Download From: [email protected] Date: Thu, 4 Oct 2012 23:09:03 -0400 To: [email protected]; [email protected]; [email protected] Subject: [IAEP] Arduino and XO-1 Tony, I have been trying to get the Arduino to work with the XO-1 laptops.(Thanks to your great blog posts) I have successfully installed the Arduino IDE on the laptop, and it works great. Tonight, I installed the Arduino plugin for Turtle Art and (once again using your blog posts), created my first project. When I click "Start," I get an error: "Check the Arduino and the number of port." How do I do this with TurtleArt/outside the IDE? Thanks so much. Gerald _______________________________________________ IAEP -- It's An Education Project (not a laptop project!) [email protected] http://lists.sugarlabs.org/listinfo/iaep _______________________________________________ IAEP -- It's An Education Project (not a laptop project!) [email protected] http://lists.sugarlabs.org/listinfo/iaep
#!/usr/bin/env python # Copyright (c) 2012, Alan Aguiar <[email protected]> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os from time import time from gettext import gettext as _ from plugins.plugin import Plugin from TurtleArt.tapalette import make_palette from TurtleArt.talogo import media_blocks_dictionary, primitive_dictionary, logoerror import firmata import commands VALUE = {_('HIGH'): firmata.HIGH, _('LOW'): firmata.LOW} MODE = {_('INPUT'): firmata.INPUT, _('OUTPUT'): firmata.OUTPUT, _('PWM'): firmata.PWM, _('SERVO'): firmata.SERVO} ERROR = _('ERROR: Check the Arduino and the number of port.') ERROR_VALUE_A = _('ERROR: Value must be a number from 0 to 255.') ERROR_VALUE_D = _('ERROR: Value must be either HIGH or LOW.') ERROR_MODE = _('ERROR: The mode must be either INPUT, OUTPUT, PWM or SERVO.') class Arduino(Plugin): def __init__(self, parent): self.tw = parent self._dev = '/dev/ttyUSB0' self._baud = 57600 self._arduino = None status,output = commands.getstatusoutput("ls /dev/ | grep ttyUSB") output = output.split('\n') for i in output: status,aux=commands.getstatusoutput("udevinfo -a -p /class/tty/%s | grep ftdi_sio > /dev/null" % i) if (not status): self._dev='/dev/%s' % i break def setup(self): self._arduino = firmata.Arduino(port = self._dev, baudrate = self._baud) palette = make_palette('arduino', ["#00FFFF","#00A0A0"], _('Palette of Arduino blocks')) primitive_dictionary['pinmode'] = self._prim_pin_mode palette.add_block('pinmode', style='basic-style-2arg', label=[_('pin mode'),_('pin'),_('mode')], help_string=_('Select the pin function (INPUT, OUTPUT, PWM, SERVO).'), prim_name='pinmode') self.tw.lc.def_prim('pinmode', 2, lambda self, x, y: primitive_dictionary['pinmode'](x, y)) primitive_dictionary['analogwrite'] = self._prim_analog_write palette.add_block('analogwrite', style='basic-style-2arg', label=[_('analog write'),_('pin'),_('value')], default=[0, 255], help_string=_('Write analog value in specified port.'), prim_name='analogwrite') self.tw.lc.def_prim('analogwrite', 2, lambda self, x, y: primitive_dictionary['analogwrite'](x, y)) primitive_dictionary['analogread'] = self._prim_analog_read palette.add_block('analogread', style='basic-style-1arg', label=[_('analog read')], default=[0], help_string=_('Read value from analog port. Value may be between 0 and 1023. Use Vref \ to determine voltage. For USB, volt=((read)*5)/1024) approximately.'), prim_name='analogread') self.tw.lc.def_prim('analogread', 1, lambda self, x: primitive_dictionary['analogread'](x)) primitive_dictionary['digitalwrite'] = self._prim_digital_write palette.add_block('digitalwrite', style='basic-style-2arg', label=[_('digital write'),_('pin'),_('value')], default=[13], help_string=_('Write digital value to specified port.'), prim_name='digitalwrite') self.tw.lc.def_prim('digitalwrite', 2, lambda self, x, y: primitive_dictionary['digitalwrite'](x, y)) primitive_dictionary['digitalread'] = self._prim_digital_read palette.add_block('digitalread', style='basic-style-1arg', label=[_('digital read')], default=[13], help_string=_('Read value from digital port.'), prim_name='digitalread') self.tw.lc.def_prim('digitalread', 1, lambda self, x: primitive_dictionary['digitalread'](x)) primitive_dictionary['high'] = self._prim_high palette.add_block('high', style='box-style', label=_('HIGH'), help_string=_('Set HIGH value for digital port.'), prim_name='high') self.tw.lc.def_prim('high', 0, lambda self: primitive_dictionary['high']()) primitive_dictionary['input'] = self._prim_input palette.add_block('input', style='box-style', label=_('INPUT'), help_string=_('Configure Arduino port for digital input.'), prim_name='input') self.tw.lc.def_prim('input', 0, lambda self: primitive_dictionary['input']()) primitive_dictionary['servo'] = self._prim_servo palette.add_block('servo', style='box-style', label=_('SERVO'), help_string=_('Configure Arduino port to drive a servo.'), prim_name='servo') self.tw.lc.def_prim('servo', 0, lambda self: primitive_dictionary['servo']()) primitive_dictionary['low'] = self._prim_low palette.add_block('low', style='box-style', label=_('LOW'), help_string=_('Set LOW value for digital port.'), prim_name='low') self.tw.lc.def_prim('low', 0, lambda self: primitive_dictionary['low']()) primitive_dictionary['output'] = self._prim_output palette.add_block('output', style='box-style', label=_('OUTPUT'), help_string=_('Configure Arduino port for digital output.'), prim_name='output') self.tw.lc.def_prim('output', 0, lambda self: primitive_dictionary['output']()) primitive_dictionary['pwm'] = self._prim_pwm palette.add_block('pwm', style='box-style', label=_('PWM'), help_string=_('Configure Arduino port for PWM (pulse-width modulation).'), prim_name='pwm') self.tw.lc.def_prim('pwm', 0, lambda self: primitive_dictionary['pwm']()) def start(self): pass def quit(self): pass def stop(self): pass def clear(self): pass def _check_init(self): if self._arduino: self._arduino.parse() def _prim_pin_mode(self, pin, mode): self._check_init() mode = MODE[mode] self._arduino.pin_mode(int(pin), mode) def _prim_analog_write(self, pin, value): self._check_init() value = int(value) self._arduino.analog_write(int(pin), value) def _prim_digital_write(self, pin, value): self._check_init() value = VALUE[value] self._arduino.digital_write(int(pin), value) def _prim_analog_read(self, pin): self._check_init() self._arduino.parse() res = -1 res = self._arduino.analog_read(int(pin)) return res def _prim_digital_read(self, pin): self._check_init() self._arduino.parse() res = -1 res = self._arduino.digital_read(int(pin)) if res == VALUE[_('HIGH')]: res = _('HIGH') elif res == VALUE[_('LOW')]: res = _('LOW') return res def _prim_high(self): return _('HIGH') def _prim_low(self): return _('LOW') def _prim_input(self): return _('INPUT') def _prim_output(self): return _('OUTPUT') def _prim_pwm(self): return _('PWM') def _prim_servo(self): return _('SERVO')
_______________________________________________ IAEP -- It's An Education Project (not a laptop project!) [email protected] http://lists.sugarlabs.org/listinfo/iaep
