Commit baef2e7dc95ca6bbe5549168bbb49bfd74e4f80d

Authored by Christopher Stone
1 parent 1e2a1faf
Exists in master

Initial testing of bluetooth serial module. It works, but the code is currently …

…still rather messy. Hardcoded virtual serial port arrangements into programmes for each end.
robots/little_john/telemetry/code/monitor/colours.pyc
No preview for this file type
robots/little_john/telemetry/code/monitor/graph_plotter.py
1   -#!/usr/bin/env python
  1 +#!/usr/bin/env python2
2 2  
3 3 import pyglet
4 4 import math
... ... @@ -6,14 +6,18 @@ import random
6 6 import time
7 7 import serial
8 8  
9   -datafeed = serial.Serial(
10   - port='/dev/ttyUSB0',
11   - baudrate = 9600,
12   - parity=serial.PARITY_NONE,
13   - stopbits=serial.STOPBITS_ONE,
14   - bytesize=serial.EIGHTBITS,
15   - timeout=1
16   -)
  9 +try:
  10 + datafeed = serial.Serial(
  11 + port='/dev/rfcomm0',
  12 + baudrate = 115200,
  13 + parity=serial.PARITY_NONE,
  14 + stopbits=serial.STOPBITS_ONE,
  15 + bytesize=serial.EIGHTBITS,
  16 + timeout=1
  17 + )
  18 +except:
  19 + print("Serial port setup failure; exiting")
  20 + exit()
17 21  
18 22 red = [1, 0, 0]
19 23 green = [0, 1, 0]
... ... @@ -33,12 +37,12 @@ def drawgrid(target, xlines, ylines, xlimits, ylimits):
33 37 for xpos in range(0, target.width, target.width/xlines):
34 38 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (xpos, 0, xpos, target.height)))
35 39 tagtext = str(round((xlimits[1]-xlimits[0])*(float(xpos)/target.width) + xlimits[0], 1))
36   - tag = pyglet.text.Label(tagtext, font_name='Arkhip', font_size=10, x=xpos-2, y=0, anchor_x='right', anchor_y='bottom')
  40 + tag = pyglet.text.Label(tagtext, font_name='Sans', font_size=10, x=xpos-2, y=0, anchor_x='right', anchor_y='bottom')
37 41 tag.draw()
38 42 for ypos in range(0, target.width, target.height/ylines):
39 43 pyglet.graphics.draw(2, pyglet.gl.GL_LINES, ('v2i', (0, ypos, target.width, ypos)))
40 44 tagtext = str(round((ylimits[1]-ylimits[0])*(float(ypos)/target.height) + ylimits[0], 1))
41   - tag = pyglet.text.Label(tagtext, font_name='Arkhip', font_size=10, x=0, y=ypos-2, anchor_x='left', anchor_y='top')
  45 + tag = pyglet.text.Label(tagtext, font_name='Sans', font_size=10, x=0, y=ypos-2, anchor_x='left', anchor_y='top')
42 46 tag.draw()
43 47  
44 48  
... ... @@ -86,7 +90,7 @@ def poll_serial(foo):
86 90 except:
87 91 pass
88 92  
89   -pyglet.clock.schedule_interval(poll_serial, 0.01)
  93 +pyglet.clock.schedule_interval(poll_serial, 0.001)
90 94  
91 95 def drawgraph(target, xpoints, ypoints, colour):
92 96 plotline(target, xpoints, ypoints, colour)
... ... @@ -102,4 +106,4 @@ def on_draw():
102 106 window1.clear()
103 107 drawgraph(window1, xdata, y1data, green)
104 108  
105   -pyglet.app.run()
106 109 \ No newline at end of file
  110 +pyglet.app.run()
... ...
robots/little_john/telemetry/code/robot/analogread_demo/analogread_demo.ino
... ... @@ -7,9 +7,14 @@
7 7 */
8 8  
9 9 #include <math.h>
  10 +#include <SoftwareSerial.h>
  11 +
  12 +SoftwareSerial Bluetooth(3, 2); // Rx, Tx
10 13  
11 14 void setup() {
12 15 Serial.begin(9600);
  16 + Bluetooth.begin(115200);
  17 + //Bluetooth.print("Hello, wireless world!");
13 18 pinMode(13, OUTPUT);
14 19 }
15 20  
... ... @@ -17,8 +22,8 @@ void loop() {
17 22 float a0value = analogRead(A0);
18 23 float a7value = analogRead(A7);
19 24  
20   - Serial.print(a0value);
21   - Serial.print(", ");
22   - Serial.println(a7value);
23   - delay(20);
  25 + Bluetooth.print(a0value);
  26 + Bluetooth.print(", ");
  27 + Bluetooth.println(a7value);
  28 + delay(500);
24 29 }
... ...