I've previously had my Arduino kit working on the same hardware with Breakout, but would like to switch to Johnny Five. My hardware is wired with the simple single LED layout from http://weblog.bocoup.com/javascript-arduino-programming-with-nodejs/ but running the basic LED strobing demo isn't working as expected:
var five = require("johnny-five"),
board, led;
board = new five.Board();
board.on("ready", function() {
console.log('ready');
led = new five.Led(13);
led.strobe(100);
});
Returns:
1341154189666 Board Connecting...
1341154189697 Serial Found possible serial port cu.usbmodem621
1341154189699 Board -> Serialport connected cu.usbmodem621
1341154191570 Repl Successfully Connected
I end up straight in the Firmata REPL with no LED strobing, and board.ready is false.
Any suggestions for why the board.ready callback wouldn't be firing?
On Windows, sometimes you have to specify which COM port. I received the following error when flashing firmata:
avrdude: stk500_getsync(): not in sync: resp=0x00
Change the Arduino UI to point to the other COM port (COM4 in my case)
Tools -> Serial Port -> COM4
Add this to your johnny-five startup code:
var five = require("johnny-five");
board = new five.Board({
port: "COM4"
});
board.on("ready", ...);
I was running into this same problem on my Arduino Uno R3 with johnny-five. To fix it, I had to update the StandardFirmata.
Download the latest Arduino software (at time of writing 1.0.2)
Install and open the Arduino application
Connect the Arduino to the computer (through USB)
In the menu, select File > Examples > Firmata > StandardFirmata
Press the upload button
After that completed, I could connect to the board using firmata and the ready event fired as expected. I had to do the same process with all my Arduinos to get them to work.
Related
I'm trying figure out how to control multiple temperature sensors.
THE SETUP:
2 ESP8266 Micro Controllers
2 MCP9808 Temperature Sensors
1 Machine controlling both ESPs using Johnny-Five.
NOTE: Each ESP8266 micro controller handles one MCP9808 Temperature Sensor.
THE GOAL:
The central machine (MacOS running Johnny-Five) handles both microcontrollers under one Node JS script.
THE PROBLEM:
I can control one Micro Controller / Temperature pairing, but not both under the same script.
Apparently the key to handling both at once lies in knowing how to handle the IC2 addressing.
So far I haven't been able to find any pages, forums, instructions or combinations thereof that clearly explain the logic in terms that I can understand.
THE QUESTION:
How to handle I2C using Johnny-Five to control multiple devices
THE CODE:
It only works when handling one Sensor, not both
In other words with the 4th line commented out it works. Uncommented, it doesn't.
var five = require("johnny-five");
var {EtherPortClient}=require("etherport-client");
var Thermometers=[
//{Name:"Thermometer1", Ip:"192.168.1.101"}, //Uncommenting causes fail.
{Name:"Thermometer2", Ip:"192.168.1.102"}
];
TrackThermometers();
function TrackThermometers(){
Thermometers.forEach(function(ThisThermometer, ThermometerCount){
ThisThermometer.Board=new five.Board({
port: new EtherPortClient({
host: ThisThermometer.Ip,
port: 3030
}),
repl: false
});
ThisThermometer.Board.on("ready", function(){
ThisThermometer.Controller=new five.Thermometer({ //This cmd triggers the error
controller:"MCP9808"
});
ThisThermometer.Controller.on("change", function(){
console.log(this.id, this.fahrenheit);
});
})
});
}
SOLUTION
There is a board property (undocumented as of this post) under the J5's Thermometer API. Assigning the Board instance in question to that property associates the Thermometer instance with that board.
By way of example the above code would be edited as follows...
ThisThermometer.Controller=new five.Thermometer({
board: ThisThermometer.Board, //<-- the missing magic
controller:"MCP9808"
});
Thanks to Donovan Buck for figuring this out. May be documented soon.
I'm currently trying to use node on a raspberry pi to host a HTTP server using socket.io to control it.
I currently have WASD keys binded to events ( forward, left, right, and back ) when I press the corresponding keys use light up LED's using code like this:
if( data.forward ) {
console.log('forward - ON');
wpi.digitalWrite(forwardPin, 1 );
} else {
console.log('forward - OFF');
wpi.digitalWrite(forwardPin, 0 );
}
This will turn off and on a LED. Now this is working, i want to now send hijack the controller of this tank i have bought.
Doing this my mimicking the signal the radio receiver sends out.
This guy has done this but in C : https://github.com/ianrenton/raspberrytank/blob/e311504642266d153ee434c85f91724a37403476/rt_ssh.c
You can see the codes in his code which are the same codes for my tank.
Here is one of them: int fwd_slow = 0xFE200F34;
I'm currently using this NPM module to control the GPIO pins (I'm totally open to other libs if you know better with better documentation).
Could someone show me a working example how to send "0xFE200F34" as a signal via a GPIO pin.?
Here is a link of his tutorial:
https://ianrenton.com/hardware/raspberry-tank/
I'm doing the same but in node only.
I have a problem regarding Seeedstudio Bluetooth shield http://www.seeedstudio.com/depot/Bluetooth-Shield-p-866.html
I can't detect its presence by any other devices.
The code I uploaded to Arduino is a standard example for slave device from the library:
/* Upload this sketch into Seeeduino and press reset*/
#include <SoftwareSerial.h> //Software Serial Port
#define RxD 6
#define TxD 7
#define DEBUG_ENABLED 1
SoftwareSerial blueToothSerial(RxD,TxD);
void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
}
void loop()
{
char recvChar;
while(1)
{
if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
recvChar = blueToothSerial.read();
Serial.print(recvChar);
}
if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
recvChar = Serial.read();
blueToothSerial.print(recvChar);
}
}
}
void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}
I've uploaded it to Arduino UNO, connected the shield and... Nothing.
LED marked as D1 is blinking green, and D2 is switched off. The device is not detected by none of the three devices I've tried (two computers and a smartphone).
By "not detected" I mean "hcitool returns nothing and OS based search for Bluetooth devices reports nothing". All three devices can detect each other without any problems.
I tried to connect it to other UNO board (in case the first one was damaged), but the result is the same.
I thought that the shield is somehow at fault, so I had it replaced by a new one - but the results are still the same.
Summing up:
3 extrnal devices
2 Arduinos
2 shields
Tested in all possible combinations, and still no success.
The device is powered up, because when I set it to send it's status to A1 analog port I always read 0 instead of a random value.
The only logical conclusion is that there is something wrong with the code above, but every google search I've made pointed me exactly to that file. It's from official wiki and in every example I've found. I've tried to contact Seeedstudio about it, but they didn't have anything of value to add ("try rebooting until it works").
Has anyone had similar problem, or has any advice what's wrong with the code?
I've managed to solve the problem on my own.
Two steps were required:
First of all I had to use hardware serial port (ports 0 and 1 on Arduino UNO), because for some reason SoftwareSerial doesn't work well with this shield.
Then I had to battery as power supply, since serial communication via ports 0 and 1 has lower priority than USB serial.
The disadvantage of this solution is that you lose USB communication with your PC, but fortunately I didn't need it.
EDIT: To avoid any confusion, here is an example of the code which worked for me:
void setup()
{
setupBlueToothConnection();
Serial.flush();
}
void loop()
{
for (char i = 0; i <= 254; i++)
{
Serial.print(i);
delay(1000);
}
}
void setupBlueToothConnection()
{
Serial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
Serial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
Serial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
Serial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
Serial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
Serial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
//Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
Serial.flush();
}
Please note that the modem sends answers to some of the commands, you should clean Serial buffer before reading from it.
Also, the jumpers on the shield should be connected like this: BT_TX to pin 0 and BT_RX to pin 1.
I have created a simple Bluetooth device using following components
HC05 module
Arduino Uno board (with re-programmable micro-controller)
I am wondering if it is possible to send commands from my BT device, as if these commands were sent from Bluetooth headset?
What I mean is:
we send 0x00000055 keycode - and the music pauses
(KEYCODE_MEDIA_PLAY_PAUSE)
we send 0x00000058 - previous song starts playing
(KEYCODE_MEDIA_PREVIOUS)
...
Here is the full list of keycodes which android uses: http://developer.android.com/reference/android/view/KeyEvent.html
I can probably create a separate app, which will read incoming commands and simulate headset button presses, but that is not what I want. As far as I'm concerned - some of the headsets are plug-and-play, meaning that no additional apps must be installed on android device. Here is the code I am currently use to send commands to Android phone:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
enum { LED_PIN = 6 };
enum LedState { LED_ON, LED_OFF, LED_BLINK };
LedState led_state;
void setup()
{
led_state = LED_OFF;
pinMode(LED_PIN, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(9, LOW);
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command more
}
const int COMMAND_MUSIC = 85;
void loop()
{
digitalWrite(LED_PIN, HIGH);
delay(100);
digitalWrite(LED_PIN, LOW);
delay(100);
delay(10000);
// trying to play or pause once in 10 seconds
BTSerial.write(0x00000055);
//BTSerial.print(0x00000055, HEX);
}
Both devices are paired but music player on my phone stays unaffected by these commands..Is it possible to control music player without creating a side app for "incoming commands from BT"?
Question is if your board supports AVRCP controller BT profile?
If it does you "only" need to connect against your phones AVRCP target BT profile. When you have a AVRCP BT connection there is specified commands how to pause and skip songs.
This is how the "plug and play" headset does.
Read more about Bluetooth profiles.
http://en.wikipedia.org/wiki/Bluetooth_profile
Looking at your code you have set up a serial link towards a phone.
This link uses SPP profile and you will only be able to send raw data over that link.
If this is the only profile that your BT stack on your Arduino Uno board have you will be forced to create an application on the phone side to be able to read the raw data and do something with it e.g. pause music.
Hope this cleared things little for you.
Probably it is to late for you, but maybe I can help someone else.
Firstly, Bluetooth devices like BT headphones, keyboards etc, are known as HID (Human Interface devices). HC05 are not one of this out of the box, but there is a solution introduced by Evan Kale (link: https://www.youtube.com/watch?v=BBqsVKMYz1I) how to update one of this using serial port connection.
Other solution is to buy BT HID module, but they are more expensive (about 10 times)
I'm trying to have my Arduino UNO board to work with a BlueSmirf Gold (http://www.sparkfun.com/products/10268).
I wired it as explained on various tutorial (for example here: http://www.instructables.com/id/how-to-Control-arduino-by-bluetooth-from-PC-pock/)
I've set the baud rate to 9600 as explained here: http://forum.sparkfun.com/viewtopic.php?p=94557
I manage to connect to it using the default Arduino serial terminal, ZTerm and my phone (using Amarino). In every cases, the green light on the bluetooth modem turns on, so until there it looks good.
The main problem is that my modem does not seem to be able to send/receive anything (the only time I've had any response was when I've set the baud rate to 9600).
For example, I have this code (simplified here, but the main idea is there):
int out_pin = 2;
String readLine() {
char command[100];
int i = 0;
if(Serial.available()){
delay(100);
while( Serial.available() > 0 && i< 99) {
command[i++] = Serial.read();
}
command[i++]='\0';
Serial.flush();
}
Serial.print("command: ");
Serial.println(command);
return (String) command;
}
void menu() {
if (Serial.available() <= 0) {
return;
}
String command = readLine();
// Do thing based on the command
}
void setup() {
pinMode(out_pin, OUTPUT);
Serial.begin(9600);
}
void loop() {
menu();
}
Logically, when I send something via the terminal, I should get it back (which is what happens when using the usb serial).
When I connect to the board via Bluetooth, it just stays silent.
I also tried this piece of code:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Spam ...");
}
Works fine when using the usb serial, but I get nothing when using bluetooth to connect to my board.
With both codes, I also tried to use the monitor tool in Amarino to send messages to the board, but it seems that it never got it.
I've tried various other things:
- do not have the USB serial available (I powered the Arduino board via USB but using a plug wall adapter. I'll try later on with a 9V battery but I don't have it available at the moment)
- do not connect CTS-1 to RTS-0 in the modem (some tutorial tell to connect them, the other don't. So as I doubted I tried both solutions).
The only time I've had something that looked like a communication was with this setup:
Arduino - Phone connected via Bluetooth
The Amarino monitoring was on
Arduino - Computer connected via the USB serial
When uploading the new code to my board, some parts of it were displayed on the monitoring tool on the phone.
It happened one or twice and I can't reproduce it now.
I'm pretty sure I've done something wrong somewhere (it seems at least it's the most logical explanation) but I'm also wondering if it could not be a problem with the Bluetooth model (I mean, even the sample tutorials do not work).
So the questions are:
is there something I missed/forgot to do that could help me solve the
problem ?
if not: is there a simple way to check that my Bluetooth modem
works fine ?
Thanks,
Vincent
I still don't have the answer on the second question ("is there a simple way to check that my Bluetooth modem works fine ?") but I've finally be able to send/receive messages from the Bluetooth modem.
As I was guessing (at least how I understand it) that was a problem with the two serials (Bluetooth and USB) on the same board.
To solve that, I've plugged the BT TX-1 on pin digital 5, RX-0 on digital 3 and used the following code (based on the SoftwareSerial tutorial):
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(5, 3);
void setup()
{
// Start the hardware serial port
Serial.begin(9600);
bluetooth.begin(9600);
}
void loop()
{
bluetooth.listen();
// while there is data coming in, read it
// and send to the hardware serial port:
while (bluetooth.available() > 0) {
char inByte = bluetooth.read();
Serial.write(inByte);
}
}
It sends all entries received from Bluetooth on the default serial (in my case USB).
I've checked with Amarino and messages sent from my phone are displayed in the Arduino serial monitor.
Same problem here. I tried connect vice versa the 0 and 1, RX and TX(i.e. RX to RX and TX to TX) and I got some communication of gibberish as opposed to nothing at all.