Things used in this project

Hardware components:
R8326274 01
Raspberry Pi 2 Model B
×1
HC-06 Bluetooth Module
×1
Software apps and online services:
BlueTerm

Schematics

0Bwb6txz85JFCSUJnvkH.png
0bwb6txz85jfcsujnvkh

Code

Bluetooth Terminal for R pi codePython
This is the Code for connecting your R pi to your smartphone over Bluetooth.
import subprocess
import select
import serial
 
 
class SerialComm:
    def __init__(self):
        self.port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=1)
 
    def read_serial(self):
        res = self.port.read(50)
        if len(res):
            return res.splitlines()
        else:
            return []
 
    def send_serial(self, text):
        self.port.write(text)
 
 
class ShellWrapper:
    def __init__(self):
        self.ps = subprocess.Popen(['bash'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
 
    def execute_command(self, command):
        self.ps.stdin.write(command + "\n")
 
    def get_output(self):
        timeout = False
        time_limit = .5
        lines = []
        while not timeout:
            poll_result = select.select([self.ps.stdout, self.ps.stderr], [], [], time_limit)[0]
            if len(poll_result):
                for p in poll_result:
                    lines.append(p.readline())
            else:
                timeout = True
        return lines
 
 
def main():
    shell = ShellWrapper()
    ble_comm = SerialComm()
    while True:
        out = ble_comm.read_serial()
        for ble_line in out:
            print(out)
            shell.execute_command(ble_line)
            shell_out = shell.get_output()
            for l in shell_out:
                print(l)
                ble_comm.send_serial(l)
 
 
if __name__ == "__main__":
    main()

Credits

Icon
Josh From BreakoutBros.com

At BreakoutBros we try to be a link between electronics designers and hobbyists. We make electronics tinkering easy for everyone but teach professional methods.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Raspberry Pi Motion Tracking Gun Turret
Intermediate
  • 54
  • 3

Full instructions

A motion tracking airsoft or nerf gun turret with autonomous and manual operation modes, controlled by a Raspberry Pi.

LoRaWAN for Raspberry Pi with Worldwide Frequency Support
Intermediate
  • 3,985
  • 18

Full instructions

LoRaWAN LMIC 1.6 for Raspberry Pi with Dragino LoRA/GPS HAT or standalone RFM95W LoRa Module.

Audio DAC Hat for Pi with Headphone Jack and 3W Speaker Out
Intermediate
  • 49
  • 2

Full instructions

Make your own DAC hat for Raspberry Pi 3, Raspberry Pi Zero, Raspberry Pi Zero W that has a Headphone jack and 3W Stereo speaker out.

Human-Following Robot with Kinect
Intermediate
  • 2,667
  • 24

Full instructions

Instead of using single camera and complicated image recognition algorithms we can take advantage of Kinect libraries.

Automated Indoor Gardener
Intermediate
  • 4,084
  • 41

Full instructions

Never worry about dead plants again. This automated gardener never forgets to water your plants and provide artificial sunlight.

Computerception
Intermediate
  • 27,548
  • 20

Full instructions

Why not put a Raspberry Pi into a 2007 netbook?

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog