domingo, 4 de junio de 2017
Octave: Fit Gaussian to data
% Adjust a gaussian
% Define the gaussian function
gausFun = @(hms,x) hms(1) .* exp (-(x-hms(2)).^2 ./ (2*hms(3)^2)) ;
init=[100;0;20]; % Hmax, mean, sigma
[P, FY, CVG, OUTP] = nonlin_curvefit (gausFun , init', XX, NN);
%Print estimated sigma
sigma_est=P(3)
viernes, 28 de abril de 2017
Raspberry pi zero W
Enable headless operation
- Download raspbian and write to micro-SD card
- Mount on PC and, on the boot partition:
- Create an (empty) file called ssh (this enable SSH on startup)
- Create a wpa_supplicant.conf file with the following content
network={
ssid="YOUR_WIFI_SSID"
psk="YOUR_WIFI_PASSWORD"
key_mgmt=WPA-PSK
}
On Off button
Poweroff
To poweroff, follow these instructions:
Essentially:
Connect button between GPIO18 and GND
Write this python script
- #!/bin/python
- # Simple script for shutting down the raspberry Pi at the press of a button.
- # by Inderpreet Singh
- import RPi.GPIO as GPIO
- import time
- import os
- # Use the Broadcom SOC Pin numbers
- # Setup the Pin with Internal pullups enabled and PIN in reading mode.
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)
- # Our function on what to do when the button is pressed
- def Shutdown(channel):
- os.system("sudo shutdown -h now")
- # Add our function to execute when the button pressed event happens
- GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
- # Now wait!
- while 1:
- time.sleep(1)
- sudo nano /etc/rc.local
- sudo python /home/pi/Scripts/shutdown_pi.py &
Poweron
To poweron, place a button across the RUN header of the RPI zero. This is actually a reset button but when halted can bring the Pi on again.
Power Consumption
During boot, I have seen peaks of 240 mA.
After shutdown, power consumption is 30 mA.
sábado, 25 de marzo de 2017
SPICE with Python
PySpice seems to be a great tool!
Just do
git clone https://github.com/FabriceSalvaire/PySpice
and install everything that it needs:
PySpice requires the following dependencies:
The way to organize a project is to have the file.py, a folder called libraries and inside put folders with the element.lib files. These can also be put into folders to easily organize things. Then, call this
libraries_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'libraries')
spice_library = SpiceLibrary(libraries_path)
circuit.include(spice_library['2n2222a'])
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')
Resistor
circuit.R( name, +node, -node, value)
circuit.R(1, 'out', circuit.gnd, kilo(5))
Capacitor
circuit.C(1, +node, -node, value)
circuit.C(1, +node, -node, value, initial_condition=5)
BJT
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')
Results
analysis.base : the voltage of node named 'base'
Interesting features
https://github.com/FabriceSalvaire/PySpice/blob/gh-pages/downloads/voltage-divider.py
Shows how to put a voltage source defined in Python into Spice. This probably means that you can have an arbitrary function generator in Python!!!
Just do
git clone https://github.com/FabriceSalvaire/PySpice
and install everything that it needs:
PySpice requires the following dependencies:
- Python 3
- Numpy
- Matplotlib
- Ngspice
- CFFI (only required for Ngspice shared)
The way to organize a project is to have the file.py, a folder called libraries and inside put folders with the element.lib files. These can also be put into folders to easily organize things. Then, call this
libraries_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'libraries')
spice_library = SpiceLibrary(libraries_path)
circuit.include(spice_library['2n2222a'])
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')
Resistor
circuit.R( name, +node, -node, value)
circuit.R(1, 'out', circuit.gnd, kilo(5))
Capacitor
circuit.C(1, +node, -node, value)
circuit.C(1, +node, -node, value, initial_condition=5)
BJT
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')
Results
analysis.base : the voltage of node named 'base'
Interesting features
https://github.com/FabriceSalvaire/PySpice/blob/gh-pages/downloads/voltage-divider.py
Shows how to put a voltage source defined in Python into Spice. This probably means that you can have an arbitrary function generator in Python!!!
domingo, 5 de febrero de 2017
Coses sobre l'esquena i els isquiotibials
https://breakingmuscle.com/learn/2-overlooked-reasons-your-hamstrings-are-tight
https://breakingmuscle.com/learn/cant-touch-your-toes-find-and-fix-the-root-of-the-problem
https://breakingmuscle.com/learn/are-your-weak-neck-muscles-making-your-hamstrings-tight
viernes, 3 de febrero de 2017
Arduino. On és el main?
Exactament què fa un programa en Arduino?
Executa un loop com aquest: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/main.cpp
int main(void) {
init();
initVariant();
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}
Executa una vegada el setup de client i crida repetidament loop() més serialEventRun.
Tot el codi principal està aquí https://github.com/arduino/Arduino/tree/master/hardware/arduino/avr/cores/arduino
Un element important és Arduino.h (en les versions "modernes" de Arduino).
jueves, 2 de febrero de 2017
Flight Controller
One of the best tutorials I have found on flight controllers
http://blog.owenson.me/build-your-own-quadcopter-flight-controller/
http://blog.owenson.me/build-your-own-quadcopter-flight-controller/
sábado, 7 de enero de 2017
Python debugging
Install interactive debugging
sudo -H pip install ipdb
To debug a script in ipython
that uses parameters in its call:
ipython -m ipdb './xvalues.py' -- -d TUB
The parameters for the script are passed after "--"
Once you have the shell, the useful commands are:
Useful link
https://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/
sudo -H pip install ipdb
To debug a script in ipython
that uses parameters in its call:
ipython -m ipdb './xvalues.py' -- -d TUB
The parameters for the script are passed after "--"
Once you have the shell, the useful commands are:
- n "next"
- <ENTER> repeats the last command
- p "print" p variable
- s "step into"
- b "breakpoint" b. This can be interesting: break at line 25: b 25. Break when method x of object y is called b y.x
- r "continue to end of subroutine"
- c "continue till the end"
Useful link
https://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/
viernes, 6 de enero de 2017
What to do if Ubuntu freezes?
https://askubuntu.com/questions/4408/what-should-i-do-when-ubuntu-freezes
domingo, 4 de diciembre de 2016
List of packages that have been installed in Ubuntu
From http://unix.stackexchange.com/questions/288024/how-can-i-get-a-list-of-packages-that-i-have-installed-using-apt-get
This will give you a list of packages that have been installed, in the order that they were installed:
zgrep -h ' install ' /var/log/dpkg.log* | sort | awk '{print $4}'
However, only the last 12 months of
/var/log/dpkg.log* files are kept by default. To change this, edit /etc/logrotate.d/{apt,dpkg}. For example, change rotate 12 to rotate 1200 to keep the last 1200 months (100 years) worth - effectively forever, never delete the old logs. Use
dpkg to list all packages installed on a system: dpkg --get-selectionsballlalalala
Suscribirse a:
Entradas (Atom)