Atmega1284p + nrF8001 Bluetooth Module

Hi everyone,

I would like to ask you guys for some help as to an issue I am struggling with. This is the situation.

I am working on a project using an nRF8001 Bluetooth module of Adafruit. The module has to deal with data coming from sensors and an SDcard. I tested the module out on the Arduino Uno and Mega 2560. It worked well on both microcontrollers.

The issue comes when I switch from the UNO or MEGA to the 1284p microcontroller. The 1284p is the main chip of my project. I used the UNO and Mega just to check if the module worked right.

However, when I test the Bluetooth module out on the 1284p, it does not work. I run the original code of the manufacturer (echoDemo) on the 1284p, but it does not work. I have reviewed the connections several times and I am pretty sure it is connected well. I have also checked and followed the digital pinout configuration of the 1284p. I would say everything is fine.

The "error" is that the Serial Monitor of the Arduino IDE does not show the message saying the connection is established.

After many days trying to figure out what the reason might be, I think it might be the library compatibility of "Adafruit_BLE_UART.h" library with the 1284p, because with both the UNO and the MEGA chips it works perfectly.

Any ideas???

I would really appreciate any help or advice because I do not know what to do at this moment.

Thank you so much in advance.

Regards.

P.S. Attached you will find two screenshots regarding the previous explanation

IDE_Results.pdf (22.9 KB)

You have to be more specific. You should post some schematics at first, and also some testing sketch.
How it is connected?
What is the difference in connection?
Adafruit nRF8001 can be connected via USART and SPI. Which one is used?
In principle it should work. There is no such difference between UNO, Mega and 1284P (BTW which board?) for which it couldn't work correctly.

Hi,

Thank you for your answer. Yes, you are right. I have to be more specific.

The following description is provided by the manufacturer (Adafruit) to wire the breakout board (Bluetooth module) up with the UNO or MEGA:

"Now that we have headers attached we can easily wire it up to our Arduino

VIN -- connects to the Arduino 5V pin

GND -- connects to Arduino ground

SCK -- connects to SPI clock.
On Arduino Uno/Duemilanove/328-based, thats Digital 13.
On Mega's, its Digital 52 and on
Leonardo/Micro its ICSP-3 (See SPI Connections for more details)

MISO -- connects to SPI MISO.
On Arduino Uno/Duemilanove/328-based, thats Digital 12.
On Mega's, its Digital 50 and on
Leonardo/Micro its ICSP-1 (See SPI Connections for more details)

MOSI -- connects to SPI MOSI.
On Arduino Uno/Duemilanove/328-based, thats Digital 11.
On Mega's, its Digital 51 and on
Leonardo/Micro its ICSP-4 (See SPI Connections for more details)

REQ connects to our SPI Chip Select pin. We'll be using Digital 10 but you can later change this to any pin

RST connects to Digital 9 - this is for resetting the board when we start up, you can later change this to
any pin

RDY is the interrupt out from the nRF8001, we'll connect to Digital 2 but be aware that if you want to change it, it must connect to an interrupt capable pin (see this Arduino page for which pins are interrupt-capable. Digital 2 is OK on Uno/Leonardo/Micro/Mega/etc.)"

I followed the above steps and everything worked well with UNO and MEGA.

However, when I switch from UNO or Mega to 1284p, something happens. The code is exactly the same. The attached image is the 1284p pinout that I am using.

I connect the MISO, MOSI, and SCK pins to the 5,6,7 pin respectively.

Based on the description of the manufacturer, the other three pins (REQ, RDY, and RST) can be connected to any other digital pins.

The REQ or Chip Select (SS) I connected it to the digital 4 pin. As to the RDY or Interrupt Pin, I connected to the digital 2 pin. And finally, I connected the RST pin to the digital pin number 14.

Also. I connected the Vcc and Gnd.

These are the connections I made and followed based always on the instructions provided by the manufacturer.

And this is the original code from the manufacturer:

This is an example for our nRF8001 Bluetooth Low Energy Breakout

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/1697

Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit!

Written by Kevin Townsend/KTOWN  for Adafruit Industries.
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in any redistribution
*********************************************************************/

// This version uses the internal data queing so you can treat it like Serial (kinda)!

#include <SPI.h>
#include "Adafruit_BLE_UART.h"
#include <Arduino.h>


//Here the REG, RDY, and RST are assigned to a digital output
// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11

#define ADAFRUITBLE_REQ 4      // I chose this pin because based on the Sanguino Pinout, SS or CS is 
                                                 //pin4
#define ADAFRUITBLE_RDY 2     // This should be an interrupt pin, on Uno thats #2 or #3. On 1284p, 
                                                //  pin2 is also an interrupt pin
#define ADAFRUITBLE_RST 14   // I decided to choose this pin. It might be another one

Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
/**************************************************************************/
/*!
    Configure the Arduino and start advertising with the radio
*/
/**************************************************************************/
void setup(void)
{ 
  Serial.begin(9600);
  while(!Serial); // Leonardo/Micro should wait for serial init
  Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Print echo demo"));

  // BTLEserial.setDeviceName("NEWNAME"); /* 7 characters max! */

  BTLEserial.begin();
}

/**************************************************************************/
/*!
    Constantly checks for new events on the nRF8001
*/
/**************************************************************************/
aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;

void loop()
{
  // Tell the nRF8001 to do whatever it should be working on.
  BTLEserial.pollACI();

  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();
  // If the status changed....
  if (status != laststatus) {
    // print it out!
    if (status == ACI_EVT_DEVICE_STARTED) {
        Serial.println(F("* Advertising started"));
    }
    if (status == ACI_EVT_CONNECTED) {
        Serial.println(F("* Connected!"));
    }
    if (status == ACI_EVT_DISCONNECTED) {
        Serial.println(F("* Disconnected or advertising timed out"));
    }
    // OK set the last status change to this one
    laststatus = status;
  }

  if (status == ACI_EVT_CONNECTED) {
    // Lets see if there's any data for us!
    if (BTLEserial.available()) {
      Serial.print("* "); Serial.print(BTLEserial.available()); Serial.println(F(" bytes available from BTLE"));
    }
    // OK while we still have something to read, get a character and print it out
    while (BTLEserial.available()) {
      char c = BTLEserial.read();
      Serial.print(c);
      
    }


// Next up, see if we have any data to get from the Serial console

    if (Serial.available()) {
      // Read a line from Serial
      Serial.setTimeout(100); // 100 millisecond timeout
      String s = Serial.readString();

      // We need to convert the line to bytes, no more than 20 at this time
      uint8_t sendbuffer[20];
      s.getBytes(sendbuffer, 20);
      char sendbuffersize = min(20, s.length());

      Serial.print(F("\n* Sending -> \"")); Serial.print((char *)sendbuffer); Serial.println("\"");

      // write the data
      BTLEserial.write(sendbuffer, sendbuffersize);
    }
  }
}

I do not know if I made a mistake making the connections (wiring up). I would say no. However, when running the code on the 1284p, the Serial Monitor does not show the message saying the connections have been established.

To me, it is an issue with the definitions and matching pins between the 1284p and the Bluetooth but I can not see it.

By the way, on the Arduino IDE I chose "Pinout:Sanguino" and obviously the 1284p.

I am stuck with something apparently "easy".

Any ideas???

Thank you so much in advance.

Regards.

I am stuck with something apparently "easy".

Any ideas???

Did you try altering the simple Blink sketch so that it flashes an LED on pin 5,6,7 etc ?

Hi,

Thank you for your answer.

I already tested those pins with a SD card of Adafruit also (MicroSD card breakout board+) and it worked right. The SD card only basically uses CS(chip select), DI (MISO), DO(MOSI), and CLK(Clock). It does not use RST (Reset) and RDY (interrupt pin).

When connecting the Bluetooh, I follow the explanations of Adafruit. I choose the RST and RDY pins those digital pins that I want, and update them within the code, but for some reason that I do not know yet, it does not work. I know it must be a small detail but I have spent more than a week to figure it out and have not been able to.

Any suggestion?

Thank you again.