2017-04-24 (M) Pi0 Laser Tag PiTagErrUs

Sending data across the serial port with Python has been a learning experience. If it was a matter of one Arduino talking to another Arduino, even different models, the process would be identical on both sides and probably just involved a lot of print() and read() functions. When an Arduino talks with a Raspberry Pi programmed with Python the rules are different. A print() statement in Python will display data to the screen but that has nothing to do with the Arduino. Python requires that data to be explicitly sent to the serial port. A print statement doesn’t work here, it must be a write() statement.

In Python, when a print() statement is called, multiple strings and variables can be sent in the same command by simply putting a comma between them. This was not true with the write() statement. This fact was causing a lot of trouble. In Arduino, the way to write multiple items on a single line is to use multiple print() statements as opposed to println(). This same methodology was attempted with Python’s write() command which did not permit anything of the sort. Once concatenation was used, the process worked well. In this case, it was a simple matter of placing a plus sign (+) between the items to be transmitted to the Arduino. Lesson learned.

Highlighted text showing concatenation

Since transmissions to the Arduino could be made with variables, it was now possible to get changing data back from it. The proof of this was using a different computer to transmit different “shots” while posing as a different player. This can be seen in the readout below. Since there was no error checking to see if a signal was valid, some of the shots appear as “Anonymous” which is the default when the player’s name cannot be recognized. This type of error checking should be possible to implement.

Readout showing the recognition of different shooters

Downloads:

The rest of the posts for this project have been arranged by date

First time here?

Completed projects from year 1 
Completed projects from year 2
Completed projects from year 3


Disclaimer for http://24hourengineer.blogspot.com/ and 24hourengineer.com
This disclaimer must be intact and whole. This disclaimer must be included if a project is distributed.
All information in this blog, or linked by this blog, are not to be taken as advice or solicitation. Anyone attempting to replicate, in whole or in part, is responsible for the outcome and procedure. Any loss of functionality, money, property or similar, is the responsibility of those involved in the replication.
All digital communication regarding the email address 24hourengineer@gmail.com becomes the intellectual property of Brian McEvoy. Any information contained within these messages may be distributed or retained at the discretion of Brian McEvoy. Any email sent to this address, or any email account owned by Brian McEvoy, cannot be used to claim property or assets.
Comments to the blog may be utilized or erased at the discretion of the owner. No one posting may claim property or assets based on a post.
This blog, including pictures and text, is copyright to Brian McEvoy.

2017-04-20 (Th)

Comments