Snips, raspberry, arduino

arduino

#1

Hello I am doing a voice recognition robot. I started with raspberyy and arduino,and am using Snips for voice recognition. Now my voice is recognising by Snips but no action is happening in Arduino. When i am running this code snippet directly in PI, my motor is working. But through Snips I am not getting anything.

import serial
import time
arduinoSerialData = serial.Serial(’/dev/ttyACM0’,9600)
while 1:
arduinoSerialData.write(b’2’)
time.sleep(10);
where b’2’=2 is just a value to compare in arduino.
Should i add anything else ? Please some one help me.
Thanks in advance.


#2

Hello,

I’ve moved your topic into the “Your projects” category.
Also you would get a better answer onto the Arduino forum.

I would personnaly use something like this in my Arduino code:

#define SLAVE_ADDRESS 0x04

    void loop() {
      if (Serial.available() > 0) {
        // read the incoming byte:
        int incomingByte = Serial.read();
        if (incomingByte == 'B') {
          // execute my action
 }

In my RPI I would use:

    class <yourname>:

        @classmethod
        def __init__(self, locale = "EN_US", extra = False):
            arduino_ports = [
                        p.device
                            for p in serial.tools.list_ports.comports()
                            for x in range (0, 10)
                            if 'ttyUSB%d' % x  in p.name or "ttyACM%d" % x in p.name]
            if not arduino_ports:
                    raise IOError("No Arduino found")
            if len(arduino_ports) > 1:
                    warnings.warn('Multiple Arduinos found - using the first')
            self.ser = serial.Serial(
                                port=arduino_ports[0],
                                baudrate = 9600
                            )

#3

if i want to send some values to arduino from raspberrypi how can i do?

self.ser.write(‘B%dE\n’%(value))

is it correct? or any otherways?


#4

Lots of different ways, that’s just one way yes :slight_smile:


#5

this is my code:

import serial
import serial.tools.list_ports
import sys
import time
import warnings

class vishal:
@classmethod
def init(self, locale = “EN_US”, extra = False):
arduino_ports = [
p.device
for p in serial.tools.list_ports.comports()
for x in range (0, 10)
if ‘ttyUSB%d’ % x in p.name or “ttyACM%d” % x in p.name]
if not arduino_ports:
raise IOError(“No Arduino found”)
if len(arduino_ports) > 1:
warnings.warn(‘Multiple Arduinos found - using the first’)
self.ser = serial.Serial(
port=arduino_ports[0],
baudrate = 9600
)
self.ser.write(‘B%dE\n’%(2))

////// i dont know what is the problem…may be its because of my less knowledge in Python. If anyone help me to solve the problem, it will be helpful…thanks…


#6

Indentation maybe? :slight_smile:

Just send self.ser.write(yourvalue) to start and see if you can receive it with the Arduino serial monitor.

Without logs we can’t help you, provide your code and logs.


#7

import serial
import time
arduinoSerialData = serial.Serial(’/dev/ttyACM0’,9600)
while 1:
arduinoSerialData.write(‘2’)
time.sleep(10)

//// when i was running this on my PI, it is working and and the motor connected with arduino is also running. Same code I used in Snips. What i exactly need is if snips recognise my command as “left”, it will send a value to arduino and motor should rotate acoording to that


#8

one more error I am getting is

session with id ‘19c79cb1-6716-4b89-98e5-d80c8da818f6’ was ended on site default. The session was ended because one of the component didn’t respond in a timely manner

////


#9

hello,
× Error setting up virtualenv, one or more actions might not be able to run. Reason :
: not found: setup.sh:
: not found: setup.sh:
: not found: setup.sh:
setup.sh: 22: setup.sh: Syntax error: end of file unexpected (expecting “then”)

this is error I am getting. I used the same setup file used for coffe machine. But I am not able to make virtual environment for that.
Please somebody helps me.