Arduino, Adafruit Bluefruit SPI Friend, and L298 H-bridge Module (work in progress)

Arduino, Adafruit Bluefruit SPI Friend, and L298 H-bridge Module (work in progress)

This page is at http://teachmetomake.com/wordpress/arduino-ble-l298-work-in-progress

  1. Install Adafruit Bluefruit nRF51 library
  2. Open File->Examples->Adafruit Bluefruit nRF51->Controller
  3. In the second tab (BlueFruitConfig.h) note the pin assignments for the Bluefruit module. The only thing you need to change is the -1 for BLUEFRUIT_SPI_RST:
    #define BLUEFRUIT_SPI_SCK              13
    #define BLUEFRUIT_SPI_MISO             12
    #define BLUEFRUIT_SPI_MOSI             11
    #define BLUEFRUIT_SPI_CS               8
    #define BLUEFRUIT_SPI_IRQ              7
    #define BLUEFRUIT_SPI_RST              -1

    This is how you should wire up the Bluefruit module.

  4. Wire up the L298 module to any unused pins, avoiding pins 0 and 1. Put the following somewhere near the top of the of controller source file. If you use different pins change as needed:
    #define IN1 6
    #define IN2 5
    #define IN3 4
    #define IN4 3
  5. In the setup() function add this:
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
    pinMode(IN3, OUTPUT);
    pinMode(IN4, OUTPUT);
  6. In the loop() function look for the buttons section and  the following code, replacing HIGH and LOW as needed for your particular motors:
      if (pressed) {
          if (buttnum == 5) {
            // Both motors forward
            digitalWrite(IN1, HIGH);
            digitalWrite(IN2, LOW);
            digitalWrite(IN3, HIGH);
            digitalWrite(IN4, LOW);
          }
          if (buttnum == 6) {
            // Both motors reverse
            digitalWrite(IN1, LOW);
            digitalWrite(IN2, HIGH);
            digitalWrite(IN3, LOW);
            digitalWrite(IN4, HIGH);
          }
          if (buttnum == 7) { 
            // turn left; 
            // right motor forward, left motor reverse
            digitalWrite(IN1, LOW); 
            digitalWrite(IN2, HIGH);
            digitalWrite(IN3, HIGH);
            digitalWrite(IN4, LOW);
          }
           if (buttnum == 8) { 
            // turn right; 
            // right motor reverse, left motor forward
            digitalWrite(IN1, HIGH);  
            digitalWrite(IN2, LOW);
            digitalWrite(IN3, LOW);  
            digitalWrite(IN4, HIGH);
          }
        }
        else
        {
          digitalWrite(IN1, LOW);
          digitalWrite(IN2, LOW);
          digitalWrite(IN3, LOW);
          digitalWrite(IN4, LOW);
        }
      }

The full code is here

controllermodifiedformotors

Bluefruit Tutorial

L298 H-BridgeTutorials

Important things to remember

  • Set the baud rate of the Serial Monitor to 115200
Print Friendly
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.