35
votes
Accepted
Raspberry PI controllable car (code for a 6-year old)
The implementation of forward is horrible. The only correct way of expressing it is to make all four motors go forward. As an analogy, how would you react if your ...
27
votes
Raspberry PI controllable car (code for a 6-year old)
From my experience, kids understand DRY without explanation, and in fact they are very bored by the repetition.
which led to some motors accepting "backwards" as "forward"
This is I am afraid a ...
20
votes
Accepted
Sort-of Alexa clone using Python on a Raspberry Pi
This is very interesting. I love it. Good work.
Critcism:
with sr.Microphone() as sauce:
From https://pixabay.com/photos/tomato-soup-tomato-soup-sauce-482403/
...
17
votes
Sensor logger for Raspberry Pi in a stratospheric probe
Do not call main recursively. You are setting yourself up for stack overflow. Consider instead
...
15
votes
Accepted
Car computer in python / GPS tracking
There's A LOT going on in your code but I'll try to give you some hints and some suggestions regarding the overall structure/workflow of the code.
you have really abused the use of ...
14
votes
Accepted
Raspberry PI controllable Christmas Tree
I would suggest to separate the concerns of coloring and animating. Now, in particular theater_chase_rainbow duplicates code from other methods. Instead, have ...
11
votes
Accepted
Sensor logger for Raspberry Pi in a stratospheric probe
Have you already executed the code to see how it performs and if the battery will last? There is that famous Donald Knuth quote saying premature optimization is the root of all evil (or at least most ...
10
votes
Accepted
Raspberry-Pi morse-code LED
I'm aware that you are a beginner. So I will try to improve your code starting from the most obvious problems and try advance step by step.
Variable names
Names like ...
8
votes
Sensor logger for Raspberry Pi in a stratospheric probe
Opening and closing files takes resources:
with open('babar.txt', 'a') as f: f.write('a'*10000)
takes 300 micro-seconds while:
...
8
votes
Loop to print changes in irrigation state to turn on and off a pump when water is low
Just curious, but have you checked CPU usage ? Programs that run in a while loop can be terribly inefficient and taxing. Here you are just probing a sensor, this does not look like a computationally-...
7
votes
Raspberry PI controllable car (code for a 6-year old)
I wrote a Pi+python control program so I had a quick look at what I did.
Interestingly I noticed that I seem to have had the same problem with forwards and backwards. I found this comment:
...
7
votes
Accepted
C++ code reading from a text file, storing value in int, and outputting properly rounded float
This is good use of the appropriate stream:
...
6
votes
Accepted
Measure distance using echo signal from Ultrasonic sensor
raw_ultrasonic_measure measures the duration of an echo staying high. It is not related to the distance in any way, it is just a duration of trig signal.
You need ...
6
votes
Accepted
AppJar number pad and keyboard
Python has an official style guide, PEP8. It won't hurt getting familiar with it, since it helps keeping your code readable, consistent and ready for others to mess with.
Combining Italian and ...
Mast♦
- 13.9k
6
votes
Car computer in python / GPS tracking
Other minor points:
Generators
Your generator -
for line in s:
yield line.replace('\0','')
can be simplified to
...
6
votes
Loop to print changes in irrigation state to turn on and off a pump when water is low
If I understand what you are trying to do, I think you can (1) remember the
prior state, (2) print only on changes, and (3) select the message to
print based on the new state.
...
6
votes
C++ code reading from a text file, storing value in int, and outputting properly rounded float
Naming:
Personally I find Snake case word_word_word is more of a Python style. Where Camel case wordWordWord is more C++.
...
5
votes
Accepted
5
votes
Accepted
Signal output on Raspberry Pi that acts as input for FPGA
You should start by organising your code better. Try to avoid global variables and group together code in functions.
In addition, you should learn about list comprehensions. They make initializing ...
5
votes
Accepted
Streaming H264 video from PiCamera to a JavaFX ImageView
Architectural Ideas
Let's start at the Architecture of your Application and the data transfer.
There's basically two places where we can optimize the performance of your application. I'm ignoring ...
5
votes
Alerts by phone calls for location-relevant Israel Home Front Command alerts
always running
The requirement is perfectly sensible,
but the implementation is weird and inconvenient.
make sure that the main program is running:
...
4
votes
4
votes
Measure distance using echo signal from Ultrasonic sensor
Take these comments together with the comments of others, not instead of them. They have already said much that needs saying.
...
4
votes
Sort-of Alexa clone using Python on a Raspberry Pi
Just some small things:
find_path could be neatened up a bit using any and chain from ...
4
votes
A PHP script used on my home server to download YouTube videos
Security
Command injection
I made a small patch by disabling the characters " " (space), "&", and "|".
This can easily be bypassed. Example:
...
4
votes
Accepted
Error handling on temperature sensor
Every 4th measurement fails is a pretty high error rate. The preferred course of action would be to root cause the error and fix it. Meanwhile, since the error seems to be transient, you may want to ...
4
votes
Car computer in Python / GPS tracking VERSION 2
First, I need to say that this is a really cool project; quite fun.
You ask:
Other than consistency, would you see any advantages in using python?
Bad code can be written in any language, but it's ...
4
votes
Car computer in Python / GPS tracking VERSION 2
There is a potential race condition in update_display()
...
4
votes
Accepted
Loop to print changes in irrigation state to turn on and off a pump when water is low
I agree with @Anonymous that you should not loop continuously like that, or you'll waste energy and CPU time continuously checking the values. To solve this you can just sleep, wake up every minute, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
raspberry-pi × 78python × 55
beginner × 17
python-3.x × 12
python-2.x × 12
linux × 9
c × 7
bash × 5
java × 4
c++ × 4
performance × 4
networking × 4
embedded × 4
serial-port × 4
datetime × 3
shell × 3
gui × 3
pygame × 3
server × 3
audio × 3
opencv × 3
arduino × 3
c# × 2
game × 2
multithreading × 2