Arduino BT with S60 Python proof of concept

hi,

here a proof of concept of interfacing arduinoBT with a nokia N73 phone via python for S60.
the python code is horrible (i m not really a coder) but it works and i hope that
this primitive demo leads to further developement and postings about BT and S60 MobPhones.

info about python for s60:
http://wiki.opensource.nokia.com/projects/Python_for_S60

what it does:

when the python scripts starts
it sends ascii 49 to the arduino BT which then returns the numbers 0-60
which are written into a file and stored on the memory card.
stupid i know :slight_smile: but its just a test.

the BT waits for a ascii 49 on the serial to send the numbers.

best

erich

here the arduino code:

/* Bluetooth wit S60 mobile Phone
*
*
*
*/
int i = 0; //counter
int LED = 13; // pin for LED
int RESET = 7; //reset pin for bluetooth
int val = 0; // serial port data
int track[61];

void ledblink() {
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED, LOW);
delay(100);
}

void ledblink1() {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}

void init_track() {
for (i=0; i<=60; i++) {
track = i;

  • }*
    *} *
    void reset_bt(){
  • // Reset the bluetooth interface*
  • digitalWrite(RESET, HIGH);*
  • delay(10);*
  • digitalWrite(RESET, LOW);*
  • delay(2000);*
    }
    *void config_bt(){ *
  • Serial.println("SET BT PAGEMODE 3 2000 1");*
  • Serial.println("SET BT NAME BT_Arduino");*
  • Serial.println("SET BT ROLE 0 f 7d00");*
  • Serial.println("SET CONTROL ECHO 0");*
    _ Serial.println("SET BT AUTH * 12345");_
  • Serial.println("SET CONTROL ESCAPE - 00 1");*
    *} *

void setup() {

  • reset_bt();*
  • config_bt();*
  • pinMode(LED,OUTPUT);*
  • pinMode(RESET,OUTPUT);*
  • init_track();*
  • Serial.begin(115200);*
  • ledblink();*
    }
    void loop () {
  • val = Serial.read();*
  • if (val != -1) {*
  • if (val == 49) {*
  • ledblink1();*
  • for (i=0; i<=60; i++) {*
  • Serial.print(i, BYTE);*
  • delay(10);*
  • }*
  • }*
  • }*
    }
    -----------------------------------------------------------------
    and now the python script:
    -----------------------------------------------------------------
    # Read and write from to arduino bt board
    import socket
    def bt_connect():
  • global sock*
  • arduino_addr='00:07:80:82:1F:35' #add your arduino BT adress here*
  • sock=socket.socket(socket.AF_BT, socket.SOCK_STREAM)*
  • target=(arduino_addr,1) # serial connection to arduino BT*
  • sock.connect(target)*
    def bt_send_data():
  • global sock*
  • test = "1"*
  • sock.send(test)*
    def bt_receive_data():
  • global sock*
  • i = 0*
  • buffer = []*
  • while(i <= 60):*
  • data = sock.recv(1)*
  • print str(ord(data))*
  • buffer.append(data)*
  • i = i + 1*
  • return buffer*
    bt_connect()
    bt_send_data()
    track = bt_receive_data()
    f = open('e:\track.txt','w')
    for i in range (0,60):
    _ f.write(str(ord(track*)))_
    _
    f.write("\n")*_
    f.close()
    print str("aus")
    sock.close()

hi

this is really excellent, I have been waiting to see code like this. Can you possibly make it into a tutorial that shows the step involved, so that others can profit form your research? You can sign up easily for an account in the Playground, where you can write and edit tutorials as a wiki.

D

hi daniel,

i would love to do that but the problem is actually that I know that
my python mobile code is really bad - its "just" working :slight_smile:
and i do not want to spread this bad habit. we would need somebody who has
really an idea how to make this proper with all exceptions and checks etc. .
but true i could open up a playground section where others with more
knowledge could continue to do it right.
i just wanted to make a start as i know that some people already tried
but nothing appeared so far online.

erich

ok - i started a section in the playground, i hope others will contribute to make this into a real tutorial

http://www.arduino.cc/playground/Code/SymbianS60Python

best

erich

Hi Erich

that is great, at least your semi-working code can gets shared, tested and improved by others, which is the best part of the Arduino project and community! I added your page to the tutorials page.

thanks for adding to the collective effort :slight_smile:

D