Sanyaade  Adekoya
Published © MIT

Spresense Robotics 4 [STEM/STEAM]

Bring Spresense into STEM/STEAM education. Teach with Spresense Board [6 -16yr Kids]. Enhance and extend pedagogy value of Spresense kit.

IntermediateProtip10 hours1,264
Spresense Robotics 4 [STEM/STEAM]

Things used in this project

Hardware components

Motor Shield (L239D)
×1
Spresense camera board
Sony Spresense camera board
×1
Spresense boards (main & extension)
Sony Spresense boards (main & extension)
×1
Bluetooth Low Energy (BLE) Module (Generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
MPU-9250 Sensor
×1

Software apps and online services

MicroPython
MicroPython
Scratch/Clone IDE (Porting)
Orange IDE (Porting)
MIT App Inventor
MIT App Inventor
Cordova/PhoneGap Tools

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Oscilloscope
Wire-Cutter
Twitters
Soldering iron (generic)
Soldering iron (generic)
breadboard
Wires
Jumpers

Story

Read more

Schematics

Propose and Add-on Framework Schematics

bringing more resources and interfaces to the platform

Code

SpresenseTestDrive.ino

C/C++
This is code for our initial test on the board: Copy and paste it into the Arduino IDE
void setup() {
   pinMode(LED0, OUTPUT);
   pinMode(LED1, OUTPUT);
   pinMode(LED2, OUTPUT);
   pinMode(LED3, OUTPUT);
}
void loop() {
   digitalWrite(LED0, HIGH);
   delay(100);
   digitalWrite(LED1, HIGH);
   delay(100);
   digitalWrite(LED2, HIGH);
   delay(100);
   digitalWrite(LED3, HIGH);
   delay(1000);
   digitalWrite(LED0, LOW);
   delay(100);
   digitalWrite(LED1, LOW);
   delay(100);
   digitalWrite(LED2, LOW);
   delay(100);
   digitalWrite(LED3, LOW);
   delay(1000);
}

Spresense DC-Motor Control Code

C/C++
Used in to drive robot built during this project
/* 
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2 
---->	http://www.adafruit.com/products/1438
*/

//Adapting this code for use in Sony Spresense Board to drive DC-Motor Robots
// I have about 8 Adafruit Motor Shields in stock, so let put them into use hey!

#include <Wire.h>
#include <Adafruit_MotorShield.h>

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1);
// You can also make another motor on port M2
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(2); //I am using Sony Spresense on a two wheel robot my initial testing and modification

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Adafruit Motorshield v2 - DC Motor test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  // Set the speed to start, from 0 (off) to 255 (max speed)
  myMotor1->setSpeed(150);
  myMotor2->setSpeed(150);
  
  myMotor1->run(FORWARD);
  myMotor2->run(FORWARD);
  
  // turn on motor
  myMotor1->run(RELEASE);
  myMotor2->run(RELEASE);
}

void loop() {
  uint8_t i;
  
  Serial.print("tick");

  myMotor1->run(FORWARD);
  myMotor2->run(FORWARD);
  for (i=0; i<255; i++) {
    myMotor1->setSpeed(i); 
    myMotor2->setSpeed(i); 
    delay(10);
  }
  
  for (i=255; i!=0; i--) {
    myMotor1->setSpeed(i);  
    myMotor2->setSpeed(i);
    delay(10);
  }
  
  Serial.print("Spresense Robot Going backward");

  myMotor1->run(BACKWARD);
  myMotor2->run(BACKWARD);
  for (i=0; i<255; i++) {
    myMotor1->setSpeed(i);
    myMotor2->setSpeed(i);  
    delay(10);
  }
  for (i=255; i!=0; i--) {
    myMotor1->setSpeed(i);
    myMotor2->setSpeed(i);  
    delay(10);
  }

  Serial.print("tech");
  myMotor1->run(RELEASE);
  myMotor2->run(RELEASE);
  delay(1000);
}

Credits

Sanyaade  Adekoya

Sanyaade Adekoya

18 projects • 55 followers
Lecturer/Developer/Programmer

Comments