Bluetooth Shield affects AnalogPins

Hi,

I'm trying to do some measurement on a photodiode both via USB and Bluetooth.
The problem is the USB Data is way more accurate then the Bluetooth data.

While USB data drifts between 3-4 values, Bluetooth drifts between 6-7.

The problem seems to be with the shield, because when I recive data both over USB & Bluetooth simultaneously the data is the same. Only without the shield the accuracy goes up again.

Anyone has an idea what's the problem or knows how to fix it?

Ciao
DerUser

Anyone has an idea what's the problem or knows how to fix it?

The problem is that you haven't define which shield you are talking about, you haven't described how you are powering the bluetooth device, and you haven't posted any code.

I know how to fix those problems.

The shiels I tested are

http://www.watterott.com/de/Bluetooth-Shield?xe0b85=77ef2ab38c7e687085e2a4c6540c15c9

Power over the Arduino & over an extern power supply (5V & GND Pins)

Code for Watterott Shield:

#include <SoftwareSerial.h>   //Software Serial Port
#define RxD 6
#define TxD 7
 
#define DEBUG_ENABLED  1
 
SoftwareSerial blueToothSerial(RxD,TxD);

long value;
int count = 0;
int messen = 0;

void setup () {
    pinMode(RxD, INPUT);
    pinMode(TxD, OUTPUT);
    pinMode(8, INPUT);
    Serial.begin(9600);
    setupBlueToothConnection();
    digitalWrite(8, HIGH);
}

void loop() {
  if(digitalRead(8) == 0)
  {
   messen = 1; 
  }
  if(messen == 1)
  //if(digitalRead(1) == HIGH) // Wichtig, sonst werden Tx Daten als Rx verarbeitet
  {                          // Schalter PIO[1] auf dem Bluetooth Shield muss auf A1 stehen
    if(count == 50)
    {
        blueToothSerial.println(map(value,0,51150,0,4095));
        Serial.println(map(value,0,51150,0,4095));
        value = 0;
        count = 0;
    }
    //Serial.println(count);
    value += analogRead(2);
    count++;
    //Serial.println(value);
    //delay(300);
  }
}

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=Bluetooth_Shield\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();
}

Code for Komputer Shield

/*********************************************************************
 **  Description:                                                    **
 **  This file is a sample code for your reference.                  **
 **                                                                  **
 **  Copyright (C) 2011 ElecFreaks Corp.                             **
 **  Created by ElecFreaks Robi.W /29 Sep 2011                      **
 **                                                                  **
 **  http://www.elecfreaks.com                                       **
 *********************************************************************/

long value;
int count = 0;
int messen = 0;

void setup()
{
  //Serial.begin(9600);
  Serial1.begin(38400);
  setupBlueToothConnection();
  pinMode(8, INPUT);
  digitalWrite(8, HIGH);
}

void loop()
{
  if(digitalRead(8) == 0)
  {
   messen = 1; 
  }
  if(messen == 1)
  //if(digitalRead(1) == HIGH) // Wichtig, sonst werden Tx Daten als Rx verarbeitet
  {                          // Schalter PIO[1] auf dem Bluetooth Shield muss auf A1 stehen
    if(count == 50)
    {
        Serial1.println(map(value,0,51150,0,4095));
        Serial.println(map(value,0,51150,0,4095));
        value = 0;
        count = 0;
    }
    //Serial.println(count);
    value += analogRead(2);
    count++;
    //Serial.println(value);
    //delay(300);
  }
}

void setupBlueToothConnection()
{
  Serial1.print("\r\nat\r\n"); //set the bluetooth work in slave mode
  Serial1.print("\r\nat+role=0\r\n"); //set the bluetooth name as "SeeedBTSlave"
  Serial1.print("\r\nat+init\r\n"); // Permit Paired device to connect me
  //Serial1.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  Serial1.print("\r\nat+inq\r\n"); //make the slave bluetooth inquirable 
  //Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  //blueToothSerial.flush();
}

The problem seems to be with the shield, because when I recive data both over USB & Bluetooth simultaneously the data is the same. Only without the shield the accuracy goes up again.

Let me see if I understand this. Using a USB cable, which provides a well regulated voltage, the sum of 50 analogRead() calls, with a variation of +/- 1, is +/-4.

With a unknown wallwart powering the Arduino, the sum of 50 analogRead() calls, with a variation of +/- 1, is +/- 7.

Seems perfectly reasonable to me. Or, am I missing something?

I powered the arduino with mounted shield both over USB & an extern power supply.

What's confussing me is that with a mounted Shield the pins are not as accurate as without an Shield regardless of the power source.