1

Hi Im Megan 1st year in high sch,I have a project whereby i need to make 2 micro mouse play like pac man/cat after mouse game in a maze of 16 x 16.I have no foundation at all while given this project.

1)how to make 2 or more raspberry pi communicate with one another in theory and practically? Pls tell me the steps if possible thank you.Using model A.So far i only know how to display the raspberry pi in the monitor using keyboard and mouse which the basic...

2)My supervisor ask me to learn python which i don't see the link to my project.If there is a link to my project pls tell me in which way.

3)If there are other things that i need to know please tell me.You will be a great help.

4
  • 2
    You may want to re-title your question. The current tells us nothing about your problem. I'd also consider cutting this question into two - One to cover Pi-to-Pi communication and one to cover learning Python. No one here knows anything about your project and as such we can not answer questions about your project. Finally this is the wrong forum for open ended questions.
    – mlk
    Dec 3 '13 at 9:45
  • Are you asking us to do your homework for you?
    – Chenmunka
    Dec 3 '13 at 12:44
  • @Chenmunka Maybe read the whole question first... Her project is to make 2 micro mouses to play like a pacman game in a maze of 16 x 16. Her questions are: How to make 2 or more raspberry pi communicate with eachother? and How to work with python? How is this asking to make her homework?
    – Loko
    Dec 3 '13 at 19:01
  • why do you need 2 Pis? does this project include some moving platforms, where these are supposed to be installed? do you need motion control and real time video recognition for your project as well?
    – lenik
    Dec 4 '13 at 23:49
0

Since the two RPi's are supposed to move (if I understand correctly) you will need some wireless communication (dragging wires through the maze is not a good idea...). Probably the easiest approach will be using wifi modules and a wifi accesspoint/router. (your other option is Bluetooth, but getting it configured on RPi to communicate with another would be an uphill battle - as would be getting the WiFi modules to talk to each other, without using any accesspoint)

Thanks to wifi modules and the router, both RPis will have network connectivity. Make sure to configure either them, or DHCP of the router to assign them specific IP addresses (and not randomly picked from free DHCP pool - most WiFi routers feature such option.)

With WiFi and specific addresses, the Raspberry Pi can communicate with each other over TCP/IP - or in other words, "over the Internet".

From then on, your task will be programming the communication in Python (there's no point for any other language since you'll be using Python for everything else anyway). The example piece of communication code:

Server (e.g. "cat"):

    # Echo server program
    import socket

    HOST = ''                 # Symbolic name meaning all available interfaces
    PORT = 50007              # Arbitrary non-privileged port
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((HOST, PORT))
    s.listen(1)
    conn, addr = s.accept()
    print 'Connected by', addr
    while 1:
        data = conn.recv(1024)
        if not data: break
        conn.sendall(data)
    conn.close()

Client (e.g. "mouse"):

    # Echo client program
    import socket

    HOST = 'daring.cwi.nl'    # The remote host
    PORT = 50007              # The same port as used by the server
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))
    s.sendall('Hello, world')
    data = s.recv(1024)
    s.close

[source]

In place of HOST = 'daring.cwi.nl' you'd put the IP address of 'server'. Observe sendall and recv in the above code: that's where you send or receive data between the two sides. Instead of just sending it back and forth, you'll be making other use of it in your code. Details of using Python for the remainder of your project probably exceed the scope of this question.

In case your raspberries don't need to move, probably a solution easier than WiFi would be connecting them over RS232 (Connect pins 8 <-> 10, 10 <-> 8, read/write to /dev/ttyS0 ) - but RS232 is ill-suited for wireless communication, and besides you will likely need network connectivity anyway, and WiFi provides that - not just the Pis can communicate with each other, you can communicate with them from any PC.

Not the answer you're looking for? Browse other questions tagged or ask your own question.