Controlling Arduino Mega Ramps 1.4 using Johnny-five - arduino

I want to control a Arduino Mega with a Ramps 1.4 shield using Johnny-five.
I uploaded the Standard Firmata the Arduino board and tried to run this code:
var five = require('johnny-five');
var board = new five.Board();
board.on('ready',function(){
console.log('Board is ready');
});
My error:
1448365609699 Device(s) COM3,COM5
1448365609707 Connected COM3
1448365619710 Device or Firmware Error A timeout occurred while connecting to the Board.
Please check that you've properly flashed the board with the correct firmware.
See: https://github.com/rwaldron/johnny-five/wiki/Getting-Started#trouble-shooting
enter code here
events.js:146
throw err;
^
Error: Uncaught, unspecified "error" event. ([object Object])
at Board.emit (events.js:144:17)
at Board.log (C:\Users\Digital Hammer\Documents\Electric lab playground\test\node_modules\johnny-five\lib\board.js:633:8)
at Board.(anonymous function) [as error] (C:\Users\Digital Hammer\Documents\Electric lab playground\test\node_modules\johnny-five\lib\board.js:644:14)
at Board.<anonymous> (C:\Users\Digital Hammer\Documents\Electric lab playground\test\node_modules\johnny-five\lib\board.js:414:14)
at Timer.listOnTimeout (timers.js:92:15)
Does anyone have any ideas why it does not work?

var five = require('johnny-five');
var board = new five.Board({
port :"com5"
});
board.on('ready',function(){
console.log('Board is ready');
});
The js file didn't connect to the correct port. I need to set it to the one which is COM5.

Related

Pyserial won't readline data from arduino

I have problem with reading data from my Arduino.
Here is what I send from my arduino to Pycharm:
Serial.println("ArduinoMega");
and here is my code with Pycharm which reads and compares to b'ArduinoMega':
ser = serial.Serial(port,baudrate=9600, timeout=1)
ser.write(b'\x00')
print(port)
serial.time.sleep(2)
rec = (ser.readline(len(b'ArduinoMega')))
print(rec)
if rec == b'ArduinoMega':
ser.close()
return port
ser.close()
By default, pyserial sets dtr pin high when opening new connection. Arduino boards are made to reset themselves when connected to with high dtr, so your Arduino resets when you open connection with your computer and does not initialize its serial port in time when you send your package and expect reply.
To solve this programmatically, you can change your code to:
ser = serial.Serial()
ser.port = port
ser.baudrate = 9600
ser.timeout = 1
ser.dtr = False
ser.open()
ser.write(b'\x00')
rec = ser.read(len(b'ArduinoMega')
if rec == b'ArduinoMega':
ser.close()
return port
ser.close()
Also, note change in ser.read... line.

Error on sending AT+CWJAP_DEF commands to ESP8266

I am trying to send AT commands to ESP8266 to get connected with internet with the Wifi.
When I am sending AT and AT+RST command on serial monitor then I am getting OK and ready response which seems perfect.
Then I am sending AT+CWLAP to get list of available wifi networks which is also executing correctly.
AT+CWLAP
+CWLAP:(3,"Moto",-42,"a4:70:d6:7a:fa:6c",1,25,0)
+CWLAP:(4,"PRANJAL",-95,"1c:a5:32:3d:f5:c4",1,-16,0)
+CWLAP:(2,"VIHAN",-94,"c8:3a:35:2f:1d:81",1,-21,0)
+CWLAP:(3,"Tenda",-93,"c8:3a:35:20:a9:b1",9,-4,0)
OK
Then I sent AT+CWMODE? which is also perfect.
AT+CWMODE?
+CWMODE:1
OK
Now I am trying to connect ESP8266 with above listed Wifi with this command, it is sending an ERROR on serial monitor.
AT+CWJAP_DEF="Moto","reset1234"
Error
⸮=IRe"Moto","reset1234"
ERROR
Can anyone suggest me what could be the reason of this issue ?
#include "SoftwareSerial.h"
SoftwareSerial esp8266(2, 3); // RX, TX
void setup()
{
Serial.begin(9600); // serial port used for debugging
esp8266.begin(9600); // your ESP's baud rate might be different
}
void loop()
{
if(esp8266.available()) // check if the ESP is sending a message
{
while(esp8266.available())
{
char c = esp8266.read(); // read the next character.
Serial.write(c); // writes data to the serial monitor
}
}
if(Serial.available())
{
delay(10); // wait to let all the input command in the serial buffer
// read the input command in a string
String cmd = "";
while(Serial.available())
{
cmd += (char)Serial.read();
}
// send to the esp8266
esp8266.println(cmd);
}
}
The current official AT command set seems to be documented on https://github.com/espressif/ESP8266_AT/wiki/AT_Description
http://espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf
https://www.itead.cc/wiki/ESP8266_Serial_WIFI_Module#AT_Commands
If the module is to be configured as a client, i.e. to connect to an access point, the following AT commands have to be sent (11500 baud 8N1, CR-LF line termination):
AT+RST
AT+CWMODE=3 (1 is "Station" only (wifi client), 3 is mixed mode "Station and Access-Point", both should work)
AT+CWJAP="Moto","reset1234"
AT+CWJAP_CUR="Moto","reset1234" (temporary) or
AT+CWJAP_DEF="Moto","reset1234" (stored)
For reference, a "success story" (ESP8266 module with USB-UART, Software: HTerm, Access Point with WPA2 (both TKIP / CCMP tested)):
AT<\r><\r><\n><\r><\n>
OK<\r><\n>
AT+RST<\r><\r><\n><\r><\n>
OK<\r><\n>
<\r><\n>
ets Jan 8 2013,rst cause:2, boot mode:(3,6)<\r><\n>
<\r><\n>
load 0x40100000, len 1856, room 16 <\r><\n>
tail 0<\r><\n>
chksum 0x63<\r><\n>
load 0x3ffe8000, len 776, room 8 <\r><\n>
tail 0<\r><\n>
chksum 0x02<\r><\n>
load 0x3ffe8310, len 552, room 8 <\r><\n>
tail 0<\r><\n>
chksum 0x79<\r><\n>
csum 0x79<\r><\n>
<\r><\n>
2nd boot version : 1.5<\r><\n>
SPI Speed : 40MHz<\r><\n>
SPI Mode : DIO<\r><\n>
SPI Flash Size & Map: 32Mbit(512KB+512KB)<\r><\n>
jump to run user1 # 1000<\r><\n>
<\r><\n>
??r?d?l<18>?<31><\0><\f>?l`<3>??s?l?<28>?<19>?<4><4><4>$ <2>??r?$<4>??<27>?<4><4>ll`<3>r$?<18>?"<\0>????"<4>l?cs|<\f>?`?22???<27>BB<18>c??o??<18>NN?<16><2><\0><2>d$??<2>d??<\0>?<4>d??<\0>ll????d??l`<2>?<2>N?<\0>????"<4>d??<28>p<4><4><2><2>???"b<4>$<4>?"prlrl<\r><\n>
Ai-Thinker Technology Co. Ltd.<\r><\n>
<\r><\n>
ready<\r><\n>
WIFI DISCONNECT<\r><\n>
AT+CWMODE?<\r><\r><\n>+CWMODE:3<\r><\n>
<\r><\n>
OK<\r><\n>
AT+CWJAP_CUR="Moto","reset1234"<\r><\r><\n>
WIFI CONNECTED<\r><\n>
WIFI GOT IP<\r><\n>
<\r><\n>
OK<\r><\n>
AT+CIFSR<\r><\r><\n>+CIFSR:APIP,"0.0.0.0"<\r><\n>
+CIFSR:APMAC,"00:00:00:00:00:00"<\r><\n>
+CIFSR:STAIP,"0.0.0.0"<\r><\n>
+CIFSR:STAMAC,"00:00:00:00:00:00"<\r><\n>
<\r><\n>
OK<\r><\n>
AT+GMR<\r><\r><\n>AT version:1.1.0.0(May 11 2016 18:09:56)<\r><\n>
SDK version:1.5.4(baaeaebb)<\r><\n>
Ai-Thinker Technology Co. Ltd.<\r><\n>
Jun 13 2016 11:29:20<\r><\n>
OK<\r><\n>
This also works with mode=1.
Major rewrite.
Questions and ideas to test:
what is your module firmware version?
access point issues (e.g. MAC address restrictions)?
power supply good?
might there be any old configuration or other code running on the module?
what is the byte code of ⸮ in the error message - Is it two bytes 0x2E2E?
are you using the Arduino serial monitor for communication?
in contrast to my comment, maybe the arduino does have an influence (timing?). Try to rule this out by
doing the pass-through character-based instead of line-based, e.g.:
(end of list, no code possible otherwise:)
loop(){
if( esp8266.available() )
Serial.write(esp8266.read());
if( Serial.available() )
esp8266.write(Serial.read());
}
keeping the AVR in reset and connecting the ESP8266 serial lines directly to the USB-UART converter
Alright! I just tried to connect with different wifi and it got connected with it. It was some kinda issue with mobile hotspot.

Interfacing with SparkFun mpu-6050 with a Texas Instruments TM4C123G LaunchPad

I am trying to interface with the MPU-6050 as part of a robotics project using the Texas Instruments TM4C123G LaunchPad. I am uploading code onto this from Energia and am using the serial monitor to see the raw data output, however I am only receiving the following output when I upload it to the micro controller and run it:
Initialising I2C devices...
Here is the code that I am trying to run:
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
MPU6050 accelgyro;
void Setup_MPU6050()
{
Wire.begin();
Serial.println("Initialising I2C devices...");
accelgyro.initialize();
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
}
void Update_MPU6050()
{
int16_t ax, ay, az;
int16_t gx, gy, gz;
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print("i");Serial.print("\t");
Serial.print(ax);Serial.print("\t");
Serial.print(ay);Serial.print("\t");
Serial.print(az);Serial.print("\t");
Serial.print(gx);Serial.print("\t");
Serial.print(gy);Serial.print("\t");
Serial.println(gz);
Serial.print("\n");
}
void setup()
{
Serial.begin(115200);
Setup_MPU6050();
}
void loop()
{
Update_MPU6050();
}
The pins on the breakout board are connected to the Launchpad as follows:
VDD -> Pin 1 (3.3v)
GND -> Pin 12 (GND)
INT -> Pin 34 (PF0)
FSYNC -> None
SCL -> Pin 13 (PD0)
SDA - > Pin 14 (PD1)
VIO -> None
CLK -> None
ASCL -> None
ASDA -> None
I have got the MPU6050 and I2Cdev libraries from GitHub and have got the Wire library from github.com/codebendercc/arduino-library-files/blob/master/libraries/Wire/Wire.h but am thinking that either the wire.begin() or accelgyro.initialize() methods are not functioning properly? I am a relative beginner when it comes to programming in this language but I am undertaking an ambitious task to create a robot for a scholarship that I am applying for, and would therefore appreciate some assistance on this subject area.
I just met the same question as you. Here is a useful linkage:
enter link description here
I referred it and added some code before
Wire.begin()
--just like this
enter image description here
then I upload it and run, it works perfectly. And there is another thing to be minded that you can't connect INT pin when you don't use DMP but when you use DMP then you must connect INT pin.
I try to explain it.
Why should we add the two lines codes? The Library is from Arduino, although Energia is compatible with Arduino programming in most cases but not always. So we should explictly acclaim something.
And why should we pay attention the interruption. Because when we use DMP we use it, if we don't connect the INT pin, it willn't work normally.

QGamepadManager does not detect controller disconnection on ubuntu

I am working on a Qt project with a drone. Me and my friends are controlling a drone with a Xbox 360 Controller.
So to detect buttons and axes we have used the QGamepadManager class which is in the gamepadmanager module. It works well ! But we have a problem with this simplified code :
while (true)
{
if (this->gamepad->isConnected()) {
cout << "gamepad connected" << endl;
} else {
cout << "gamepad disocnnected" << endl;
}
}
bool GamepadMonitor::isConnected()
{
return QGamepadManager::instance()->connectedGamepads().size() == 1;
}
On windows, the method isConnected() works well but not on Ubuntu. When we launch the application with the gamepad connected the buttons are recognized and axis too. But the disconnection is not detected. When we launch the application without the gamepad, the connection is not recognized.
I have installed the joystick package. I am on Ubuntu 16.04. I am developping with Qt 5.8.
Do you have an idea ?
EDIT : I add the dmesg output
When I connect the gamepad :
[ 330.430405] usb 3-1: new full-speed USB device number 4 using xhci_hcd
[ 330.575708] usb 3-1: New USB device found, idVendor=045e, idProduct=028e
[ 330.575714] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 330.575718] usb 3-1: Product: Controller
[ 330.575721] usb 3-1: Manufacturer: ©Microsoft Corporation
[ 330.575723] usb 3-1: SerialNumber: 1E69441
[ 331.614141] input: Microsoft X-Box 360 pad as /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/input/input23
[ 331.622581] usbcore: registered new interface driver xpad
When I disconnect it :
[ 392.733786] usb 3-1: USB disconnect, device number 4
[ 392.733995] xpad 3-1:1.0: xpad_try_sending_next_out_packet - usb_submit_urb failed with result -19
I would recommand checking if Ubuntu itself detects the disconnection, by looking at the game state, or directly at dmesg output.
As it probably is detecting it, I encourage you to then fill a bug report on Qt tracker :)

Qt5.4 QAudioOutput on Raspberry Pi With PulseAudio on the 3.5mm Audio Jack Doesn't work but Qt 5.3 Does

Qt5.3 sees the default Raspberry Pi also_output.0.analog-mono device ( 3.5 mm headphone jack ) and QAudioOutput from 5.3 successfully writes audio to that device and I can hear the audio with my headphones. This all works with default Raspbian, with PulseAudio 2.0 from apt-get, and no extra configuration. PulseAudio is run as session process and not in the System Daemon mode. Qt 5.4 does not see the device with the exact same source code and Raspbian ( except cross-compiled with Qt 5.4.0 and not Qt 5.3.2 ) and also cannot write data to it.
It gives me this error ( Please note that I've manually assigned both sys default:CARD=ALSA and 'default' but they both return the same 'snd_pcm_hw_params' error ):
Output Device name: "sysdefault:CARD=ALSA"
Output Device name: "default"
Default device is "default"
Output device is: "default"
"QAudioOutput: snd_pcm_hw_params: err = -12"
Pactl sees it:
pactl list sinks
Sink #0
State: SUSPENDED
Name: alsa_output.0.analog-mono
Description: bcm2835 ALSA Analog Mono
Driver: module-alsa-card.c
Sample Specification: u8 1ch 8000Hz
I've tried to modify /etc/pulse/default.pa with this at the bottom to force the output device:
load-module module-alsa-sink sink_name=alsa_output.0.analog-mono device=hw:0
set-default-sink alsa_output.0.analog-mono
Here is my setup code that gives the error:
// Coordinator receives Audio data
m_Format.setSampleRate(8000);
m_Format.setChannelCount(1);
m_Format.setSampleSize(8);
m_Format.setCodec("audio/pcm");
m_Format.setByteOrder(QAudioFormat::BigEndian);
m_Format.setSampleType(QAudioFormat::UnSignedInt);
QAudioDeviceInfo infoOut(QAudioDeviceInfo::defaultOutputDevice());
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) {
qDebug() << "Output Device name: " << deviceInfo.deviceName();
}
qDebug() << "Default device is" << infoOut.deviceName();
if (!infoOut.isFormatSupported(m_Format))
{
qDebug()<< "Default format not supported - trying to use nearest";
m_Format = infoOut.nearestFormat(m_Format);
}
qDebug() << "Output device is: " << infoOut.deviceName();
m_AudioOutput = new QAudioOutput(infoOut, m_Format, this);
// This data accumulates and dumps data to output
m_DataForOutput.clear();
// Now Start playing
// m_Output gets written to to send data to speakers
m_Output = m_AudioOutput->start();
What in the world is going on? How come the same configuration works with 5.3.2 and not 5.4.1. Assigning the default audio device doesn't work... What can I do here and how can I make it work? Thanks!
The answer was to run in session mode ( not a system-wide PulseAudio daemon ) and edit default.pa to look like this:
## Create the default output device
#load-module module-udev-detect tsched=0
load-module module-alsa-card device_id=0
#load-module module-alsa-card device_id=0 tsched=0 fragments=10 fragment_size=640 tsched_buffer_size=4194384 tsched_buffer_watermark=262144
#load-module module-alsa-card device_id=0 tsched=0 fragments=6 fragment_size=16 tsched_buffer_size=4194384 tsched_buffer_watermark=262144
load-module module-suspend-on-idle timeout=86400
### Load several protocols
load-module module-native-protocol-unix
### Make sure we always have a sink around, even if it is a null sink.
#load-module module-always-sink

Resources