Yes ofcourse!
I talked a bit to the people of sparkfun and now I understand that the Softwareserial library is only used when you hook it up like the tutorial I mentioned earlier...it has something to do with connecting it to the serial pins on an UNO. My current circuit that I'm trying to get working is an Arduino pro mini with a bluetooth mate attached to the header pins...which is apparently different. here's what he said:
Hi Lester.
I don't have any code for you, but what I meant by debugging code was sometimes it can be helpful to print some debugging messages in your code so you can see what's going on inside your sketch. For example, you might want to print a message that shows when you have jumped into a specific branch in your program, or you might want to print the values coming in from a sensor..
I built a toy barcode scanner for a children's museum locally. It had a IR proximity sensor that looked for something to come close by and if it did, then beep a beeper and light up a LED. I used debugging messages to output what the sensor was seeing so I could tell if the code was working. My code looked for value of 100 and if the sensor sent 100 or less, the beeper would sound. The serial monitor looked something like this:
Power up!
Initialize sensors: OK!
Starting loop.
Sensor reading:
600
601
600
610
602
599
560 (I started moving my hand toward the sensor at this point.
546 (The debug code shows this and verifies everything is functional)
502
480
475
390
310
200 (Debug messages show my hand getting closer to the sensor)
185
133
104
80 (We're in range. Reading less than 100)
Item detected!
Beeping the beeper and lighting the LED.
Timeout, back to scanning...
Sensor reading:
601
604
589
Etc...
This was helpful to keep track of what my code was doing and let me make adjustments and see what effect they had while I was making them.
It looks a bit like you are doing something similar in your code, only in your case, you are sending the same thing to the serial pins and to the bluetooth.. The problem I see with your hookup is that the bluetooth module is connected to RX and TX. Anything you send with Serial.print goes out the connector the bluetooth module is connected to (FTDI connector) and anything bluetooth.print goes to your software serial pins. Since you already have the bluetooth module on the FTDI connector, it might be easier to just leave it there and use Serial.print for bluetooth messages and create a software serial port for your debug messages. (if you even decide to use any) You could connect an FTDI to those pins if you needed to view the debug output. You can attach an FTDI to software serial pins. Since you are powering the pro mini from a lipo, you would probably want to use a 3 volt FTDI. The connection would only need ground RX and TX though and you would have to rig up a connector.
The easiest thing to do might be to eliminate your software serial and only use Serial.print. You can't use the serial monitor this way though.
Chris
So, I do understand that I need to use serial.print the way I have connected it now...I don't quite understand how to set up the debug software and why I can't use the serial monitor. If I eliminate the serial software part from the code below and power up my pro mini, than it should output the values of the accelerometer, why can't another arduino pick that up? Or processing for example? I did get to read the values from the accelerometer and process them further inside processing when connected via USB. Anyway, I hope it makes sense, here's the code:
#include <SPI.h> // Included for SFE_LSM9DS0 library
#include <Wire.h>
#include <SFE_LSM9DS0.h>
#define LSM9DS0_XM 0x1D // Would be 0x1E if SDO_XM is LOW
#define LSM9DS0_G 0x6B // Would be 0x6A if SDO_G is LOW
LSM9DS0 dof(MODE_I2C, LSM9DS0_G, LSM9DS0_XM);
#define PRINT_CALCULATED
#define PRINT_SPEED 500
#include <SoftwareSerial.h>
int bluetoothTx = 1; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 0; // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
uint16_t status = dof.begin();
}
void loop()
{
printAccel(); // Print "A: ax, ay, az"
if(bluetooth.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
Serial.print((char)bluetooth.read());
}
if(Serial.available()) // If stuff was typed in the serial monitor
{
// Send any characters the Serial monitor prints to the bluetooth
bluetooth.print((char)Serial.read());
}
delay(PRINT_SPEED);
}
void printAccel()
{
// To read from the accelerometer, you must first call the
// readAccel() function. When this exits, it'll update the
// ax, ay, and az variables with the most current data.
dof.readAccel();
// Now we can use the ax, ay, and az variables as we please.
// Either print them as raw ADC values, or calculated in g's.
Serial.println(dof.calcAccel(dof.ax), 2);
Serial.println(dof.calcAccel(dof.ay), 2);
Serial.println(dof.calcAccel(dof.az), 2);
bluetooth.println(dof.calcAccel(dof.ax), 2);
bluetooth.println(dof.calcAccel(dof.ay), 2);
bluetooth.println(dof.calcAccel(dof.az), 2);
}