LOFI Blocks

LOFI Blocks © CC BY-NC

LOFI Blocks is an app and a robot recipe that will help you learn (or teach others!) how to control ROBOTS.

  • 2,679 views
  • 1 comment
  • 9 respects

Components and supplies

Necessary tools and machines

Lasercutter
Laser cutter (generic)

Apps and online services

About this project

LOFI Blocks is an app and a robot recipe that will help you learn (or teach others!) how to control ROBOTS.

By snapping colorful blocks you will learn principles of programming and code your robot to avoid obstacles, follow light and do plenty of other things.

How to get the robot?

  • BUILD IT YOURSELF! - if you have an Arduino board together with some basic electronic components you can make a DIY version of LOFI Robot from our recipe that will work with LOFI Blocks app.
  • GET OUR KIT - if you would like to have an all-inclusive package with all the parts needed to build the robot and user friendly LOFI Brain controller order our LOFI Robot - EDUBOX kit.

What is on your board?

  • Connects with LOFI Robot or any other Arduino based robot.
  • Blocks for controlling two DC motors, four analog inputs, four analog outputs (PWM or servo), distance sensor and buzzer.
  • Built in gamepad and accelerometer to control your robot.
  • Built in inputs monitor and a basic console to simplify debuging

Configuration

  • If you are using Android pair your device with Bluetooth module. If you are using iOS pairing is not necessary.
  • Upload LOFI Robot firmware to your LOFI Brain controller or other Arduino that tyou are using.
  • Install LOFI Blocks app on your device.
  • Lounch the app and click robot head icon in the top-right corner, connection panel will appear with list of available robots that you can connect to.
  • If the app connects properly with the robot a round outline wiil appear on the robot head icon.
  • You can start to code!

Available versions

  • Online - works on Chrome (in progress)
  • Ofline - Windows and Mac OSX (in progress)

You can find firmware for Arduino Leonardo in our DIY recipe page.

BEWARE ;-)

LOFI Blocks is in public beta. Please send us any comments and feedback on

What we are working on:

  • Bluetooth 4.0 support on Android
  • Compass suport
  • Adding RANDOM NUMBER and MAP TO RANGE blocks
  • Translate to more languages
  • JUNIOR version - with icons instead of text commands

Help us translate LOFI blocks!

If you would like to have the app in your language please help us with translation. It takes about 15 minutes to translate basic commands. Write us on for details.

Code

Arduino Leonardo FirmwareArduino
LOFI Robot firmware for Arduino Leonardo compatible boards.
// LOFI Brain firmware to communicate with LOFI Robot ScratchX Chrome Plugin, LOFI Blocks App and LOFI Control App
// USB + Bluetooth version
// Author: Maciej Wojnicki
// WWW.LOFIROBOT.COM

#include <Servo.h>

//data sending (arduino->computer) interval
//raise it if you encouter communication jitter
const long interval = 100;

int analog1 = 0;
int analog2 = 0;
int analog3 = 0;
int analog4 = 0;
int trigPin = 11;
int echoPin = 12;
int dist;
int current_byte = 0;
int prev_byte = 0;

unsigned long previousMillis = 0;
unsigned long currentMillis;


Servo serwo1;
Servo serwo2;
Servo serwo3;
Servo serwo4;

void setup() {
  Serial.begin(57600);
  Serial1.begin(57600);

  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);

  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(5, OUTPUT);

  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(6, OUTPUT);

  pinMode(13, OUTPUT);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

}

void loop() {

  currentMillis = millis();

  //receiving data from ScratchX Chrome plugin
  receiving();

  // timer delay reduce data bandwidth
  if (currentMillis - previousMillis >= interval) {

    previousMillis = currentMillis;

    //sending data to ScratchX Chrome plugin
    sending();

  }
 
}



void odleglosc() {

  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);

  delayMicroseconds(5); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH, 5000);
  distance = (duration / 2) / 29.1;

  //Serial.print(distance);
  //Serial.println(" cm");

  //delay(20);

  dist = distance;
}

void receiving() {

  // 201 - buzzer
  // 202 - motor1
  // 203 - motor2

  if (Serial.available() > 0) {
    current_byte = Serial.read();
    //Serial.print(recieved);

    //buzzer
    if (prev_byte == 201) {
      digitalWrite(13, current_byte);
    }
    outputs_set();
    prev_byte = current_byte;

  }

  //bluetooth
  if (Serial1.available() > 0) {
    current_byte = Serial1.read();
    //Serial.print(recieved);

    //buzzer
    if (prev_byte == 201) {
      digitalWrite(13, current_byte);
    }
    outputs_set();
    prev_byte = current_byte;
  }



}


void outputs_set() {

  //motor1
  if (prev_byte == 202) {

    if (current_byte <= 100) {
      digitalWrite(2, HIGH);
      digitalWrite(4, LOW);
      analogWrite(3, current_byte * 2.35);
    }

    if (current_byte > 100) {
      digitalWrite(4, HIGH);
      digitalWrite(2, LOW);
      analogWrite(3, (current_byte - 100) * 2.35);
    }

  }

  //motor2
  if (prev_byte == 203) {

    if (current_byte <= 100) {
      digitalWrite(7, HIGH);
      digitalWrite(8, LOW);
      analogWrite(5, current_byte * 2.35);
    }

    if (current_byte > 100) {
      digitalWrite(8, HIGH);
      digitalWrite(7, LOW);
      analogWrite(5, (current_byte - 100) * 2.35);
    }

  }

  //output1
  if (prev_byte == 204) {
    analogWrite(10, current_byte * 2.55);
  }
  //output2
  if (prev_byte == 205) {
    analogWrite(9, current_byte * 2.55);
  }
  //output3
  if (prev_byte == 206) {
    analogWrite(6, current_byte * 2.55);
  }
  //output4
  if (prev_byte == 207) {
    analogWrite(5, current_byte * 2.55);
  }

  //servo output1
  if (prev_byte == 208) {
    servo1(current_byte);
  }
  //servo output2
  if (prev_byte == 209) {
    servo2(current_byte);
  }
  //servo output3
  if (prev_byte == 210) {
    servo3(current_byte);
  }
  //servo output4
  if (prev_byte == 211) {
    servo4(current_byte);
  }

  if (prev_byte == 212 && current_byte == 99) {
    servo_off();
  }



}

void sending() {

  analog1 = analogRead(0) / 10.23;
  analog2 = analogRead(1) / 10.23;
  analog3 = analogRead(2) / 10.23;
  analog4 = analogRead(3) / 10.23;

  //[224, 115, 2, 225, 102, 4, 226, 107, 5, 227, 63, 6]
  Serial.write(224);
  Serial.write(byte(analog1));
  Serial.write(225);
  Serial.write(byte(analog2));
  Serial.write(226);
  Serial.write(byte(analog3));
  Serial.write(227);
  Serial.write(byte(analog4));

  odleglosc();

  Serial.write(240);
  Serial.write(byte(dist));

  //bluetooth
  Serial1.write(224);
  Serial1.write(byte(analog1));
  Serial1.write(225);
  Serial1.write(byte(analog2));
  Serial1.write(226);
  Serial1.write(byte(analog3));
  Serial1.write(227);
  Serial1.write(byte(analog4));

  odleglosc();

  Serial1.write(240);
  Serial1.write(byte(dist));
  // last byte "i" character as a delimiter for BT2.0 on Android
  Serial1.write(105);


}

void servo1(int position) {
  serwo1.attach(10);
  serwo1.write(position * 1.8);
  //delay(5);
  //serwo.detach();
}

void servo2(int position) {
  serwo2.attach(9);
  serwo2.write(position * 1.8);
  //delay(5);
  //serwo.detach();
}
void servo3(int position) {
  serwo3.attach(6);
  serwo3.write(position * 1.8);
  //delay(5);
  //serwo.detach();
}
void servo4(int position) {
  serwo4.attach(5);
  serwo4.write(position * 1.8);
  //delay(5);
  //serwo.detach();
}

void servo_off() {
  serwo1.detach();
  serwo2.detach();
  serwo3.detach();
  serwo4.detach();
}

Schematics

LOFI Brain - DIY version
Circuit showing how to connect an HC-SR04 distance sensor, bluetooth module and a buzzer to work with LOFI Robot firmware
Arduino bt buzzer hcsr04 bb wrpqtpdqo7
LOFI Brain - DIY version 2/2
Circuit showing how to connect DC motors driver (L293D) to Arduino to work with LOFI Robot firmware
Leonardo l23d motor driver 7ualbkhci9

Comments

Similar projects you might like

Pranked! Moving Tissue Box | Circuito.io

Project tutorial by Arduino “having11” Guy

  • 5,450 views
  • 1 comment
  • 21 respects

Blockly@rduino: Create Code with Blocks

Project tutorial by LibrEduc

  • 32,742 views
  • 20 comments
  • 114 respects

BE∆ST: Bluetooth Vehicle Final Designed Chassis

Project showcase by Matthew Chiang

  • 3,440 views
  • 0 comments
  • 19 respects

Arduino Bluetooth Robot for Android Device

Project showcase by aip06

  • 3,617 views
  • 2 comments
  • 16 respects

Gorilla Robot

Project tutorial by LOFI Robot

  • 3,164 views
  • 0 comments
  • 7 respects
Add projectSign up / Login