Author: margusja
(Arduino -> Atmega328P) + RTC + MCP23008 + LCD = kell
Tuli tahtmine kella ehitada.
Vanast ajast oli olemas LCD 16X4, RTC ja arduino R3
Ullult olin soetanud LCD expanderi – https://taaralabs.eu/lcd-plug/
RTC annab kella võimaluse. Kui toide välja võtta, siis kenasti tiksub edasi ja hoiab kellaaega õigena.
MCP23008 – annab vabaks hulga arduinio porte, vastasel juhul poleks ilmselt RTC ka kuhugi panna.
Hetkel selline laiali prototüüp, kes teab kas see kuhugi kaugemale jõuabki.
Koodiosa tuleb kõvasti tuunida, hetkel suht häbi selle osa üle.
Näiteks on nädalapäev ühe päeva võrra nihkes.
Esimene versioon tõesti halba koodi – https://github.com/margusja/ArduinoRTC
Osa2
Kuna kogu arduino plaati ühe kella alla matta on minu jaoks liigne luksus, siis otsustasin selle osa eraldi Atmega328P kätte anda. Alguses oli plaan ilma välise kellata, aga hetkel on siis välise 16MH kellaga.
Ühendasin ISP atmega328P’ga:
Allikas: http://upvector.com/atmega/
Minul sai selline asi. Programmaator on mul avrispmkII
Ja oh seda õnne:
margusja@IRack:~/Documents/Arduino/hardware/breadboard/avr$ avrdude -c avrispmkII -v -p ATMEGA328P -P usb
avrdude: Version 5.11.1, compiled on Feb 12 2013 at 01:24:54
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch
System wide configuration file is “/usr/local/CrossPack-AVR-20130212/etc/avrdude.conf”
User configuration file is “/Users/margusja/.avrduderc”
User configuration file does not exist or is not a regular file, skipping
Using Port : usb
Using Programmer : avrispmkII
avrdude: usbdev_open(): Found AVRISP mkII, serno: 000200133546
AVR Part : ATMEGA328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
———– —- —– —– —- —— —— —- —— —– —– ———
eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : STK500V2
Description : Atmel AVR ISP mkII
Programmer Model: AVRISP mkII
Hardware Version: 1
Firmware Version Master : 1.23
Vtarget : 5.1 V
SCK period : 8.00 us
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK
avrdude done. Thank you.
Part 3
Peale juhtmete ümbertõstmist ja uue kivi programmeerimist on pilt ikka segane, aga arduino sai vahelt minema.
Kuna on plaanis kivil lock bitte ja fuses muuta, siis tundub, et siinkohal on ka õige praegused setingud maha kirjutada
avrdude -c avrispmkII -v -p ATMEGA328P -P usb -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h
Reading | ################################################## | 100% 0.00s
avrdude: writing output file “<stdout>”
0xff
avrdude: reading hfuse memory:
Reading | ################################################## | 100% 0.00s
avrdude: writing output file “<stdout>”
0xda
avrdude: reading efuse memory:
Reading | ################################################## | 100% 0.00s
avrdude: writing output file “<stdout>”
0x5
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK
Ja ega ma neid peast ei arvuta – http://www.engbedded.com/fusecalc/
Part 4.5 – Asja lihtsustamiseks võtsin kasutusele sisemise kella (avrdude: safemode: lfuse reads as C2).
Nüüd on prototüüp võimalikult lihtne.
Making The Internet
Vol1 – Sisu ehitamine
Internet peab paistma elus, seega peab internet vähemalt vilkuma.
Minu eesmärk oli kasutada nn vanakooli lahendust, kus vilkumisel kasutatakse kondensaatori omadust, mitte programmeerida vilkumist. Kasutasin skeemi, mis on toodud joonisel 1.
Joonis 1. Allikkas: http://cappels.org/dproj/simplest_LED_flasher/Simplest_LED_Flasher_Circuit.html
Ma 2N2222 ei leidnud, aga mul oli kodus 2N2219A, mis toimib samuti.
Kiire prototüüp toimib.
Pildil olev parempoolne kivi ei ole ühendatud.
Varsti tuleb vol2 – internet peab olema ka ilus.
Üks miljonist
Kindlasti on tuttav väljend: “Üks võimalus miljonist.” Erinevad inimesed interpreteerivad eeltoodud lauset omamoodi.
Näiteks, kui ütelda, et lotovõidu tõenäosus on 1:1000 000, siis kas see tähendab, et kui miljon inimest mängib lotot, siis keegi kindlasti võidab? Ei? Tõsi – nii see päris ei ole, kuigi tihti seda nii lahti mõtestatakse. Aga kuidas suhet 1:1000 000 siis mõista?
Seletamiseks võtame natukene lihtsama skaala – täringu. Küsime: “Kui tõenäoline on, et kuue viske jooksul ei saa me kordagi kuut silma?” Arvutatakse seda järgnevalt: (1-(1/6))^6 e 1/6 on tõenäosus, et visatakse kuus iga eraldi katse käigus. 1- on vastassündmuse jaoks. Astendaja kuus on katsete arv. Selgub, et antud arvutuse tulemus on ligikaudu 0.33 e 1/3 on tõenäosus, et kuue viske jooksu ei tule kordagi kuus. Võis siis 2/3 on tõenäosus, et tuleb kuus.
Ülaltoodust saab üsna lihtsalt tuletada üldvalemi – P(newer) = (1-(1/n))^n
Kui nüüd antud funktsiooni kuju vaadata (Joonis 1.), siis selgub, et tõenäosus katsete arvu suurenemisel praktiliselt ei suurene e võib ka väita, et miljoni viskamise korral ei saa väga kindlalt väita, et kuus ikka tuleb.
Joonis 1.
Mis aga kõige lahedam. Aastal 1690 J. Bernoulli tegeles sama probleemiga ja avastas, et katsete väga suurel hulgal allub graafik palju lihtsamale valemile – 1/e
Allikas: https://www.countbayesie.com/blog/2015/2/18/one-in-a-million-and-e
SOLR + SIREn hints
To index field as date.
Document:
{ "title": "Alice in Wonderland", "year": "1865", "date": "1865-01-01T00:00:00Z, "content": "Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do." } date field indexed as text.
{ "title": "Alice in Wonderland", "year": "1865", "date": {"_datatype_":"http://www.w3.org/2001/XMLSchema#date", "_value_": "1865-01-01T00:00:00Z"}, "content": "Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do." } date field indexed as date and you can query like:
{ "node" : { "attribute": "date", "query" : "xsd:date([NOW-10YEARS TO NOW])" } }
JOIN
fl=xxx,yyy & {!join from=id to=patient.reference}name.family:JUKS IN SQL
SELECT xxx, yyy FROM collection1 WHERE patient.reference IN (SELECT id FROM collection1 where name.family = "JUKS")
The CAP theorem
Before we get into the role of NOSQL, we must rst understand the CAP theorem. In the theory of computer science, the CAP theorem or Brewer’s theorem talks about distributed consistency. It states that it is impossible to achieve all of the following in a distributed system:
- Consistency: Every client sees the most recently updated data state
- Availability: The distributed system functions as expected, even if there are node failures
- Partition tolerance: Intermediate network failure among nodes does not impact system functioning
Although all three are impossible to achieve, any two can be achieved by the systems. That means in order to get high availability and partition tolerance, you need to sacri ce consistency. There are three types of systems:
- CA: Data is consistent between all nodes, and you can read/write from any node, while you cannot afford to let your network go down. (For example: relational databases, columnar relational stores)
- CP: Data is consistent and maintains tolerance for partitioning and preventing data going out of sync. (For example: Berkeley DB (key-value), MongoDB (document oriented), and HBase (columnar))
- AP: Nodes are online always, but they may not get you the latest data; however, they sync whenever the lines are up. (For example: Dynamo (key-value), CouchDB (document oriented), and Cassandra (columnar))
High availability can achieved through data replication; consistency is achieved by updating multiple nodes for changes in data. Relational databases are designed to achieve CA capabilities. NOSQL databases can either achieve CP or AP.
Source: Scaling Big Data with Hadoop and Solr, H. Karambelkar (2013)
bash shortcuts
No ei jää meelde. Seega endale siia väike spikker.
Moving the cursor:
Ctrl + a Go to the beginning of the line (Home) Ctrl + e Go to the End of the line (End) Ctrl + p Previous command (Up arrow) Ctrl + n Next command (Down arrow) Alt + b Back (left) one word or use Option+Right-Arrow Alt + f Forward (right) one word or use Option+Left-Arrow Ctrl + f Forward one character Ctrl + b Backward one character Ctrl + xx Toggle between the start of line and current cursor position
Editing:
Ctrl + L Clear the Screen, similar to the clear command Alt + Del Delete the Word before the cursor. Alt + d Delete the Word after the cursor. Ctrl + d Delete character under the cursor Ctrl + h Delete character before the cursor (backspace) Ctrl + w Cut the Word before the cursor to the clipboard. Ctrl + k Cut the Line after the cursor to the clipboard. Ctrl + u Cut/delete the Line before the cursor position. Alt + t Swap current word with previous Ctrl + t Swap the last two characters before the cursor (typo). Esc + t Swap the last two words before the cursor. ctrl + y Paste the last thing to be cut (yank) Alt + u UPPER capitalize every character from the cursor to the end of the current word. Alt + l Lower the case of every character from the cursor to the end of the current word. Alt + c Capitalize the character under the cursor and move to the end of the word. Alt + r Cancel the changes and put back the line as it was in the history (revert). ctrl + _ Undo TAB Tab completion for file/directory names
For example, to move to a directory ‘sample1’; Type cd sam ; then press TAB and ENTER.
type just enough characters to uniquely identify the directory you wish to open.
History:
Ctrl + r Recall the last command including the specified character(s) searches the command history as you type. Equivalent to : vim ~/.bash_history. Ctrl + p Previous command in history (i.e. walk back through the command history) Ctrl + n Next command in history (i.e. walk forward through the command history) Alt + . Use the last word of the previous command Ctrl + s Go back to the next most recent command. (beware to not execute it from a terminal because this will also launch its XOFF). Ctrl + o Execute the command found via Ctrl+r or Ctrl+s Ctrl + g Escape from history searching mode
Process control:
Ctrl + C Interrupt/Kill whatever you are running (SIGINT) Ctrl + l Clear the screen Ctrl + s Stop output to the screen (for long running verbose commands) Ctrl + q Allow output to the screen (if previously stopped using command above) Ctrl + D Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT) Ctrl + Z Send the signal SIGTSTP to the current task, which suspends it. To return to it later enter fg 'process name' (foreground).
Read logs with Apache-drill
Closures
Closures paradigm is amazing. It is supported mainly from functional languages.
Let’s make an example.
function first(x) {
function second(y) {
return x + y
}
return second(y)
}
So calling first(10) we will get return function(y) { return 10 + y}
in example:
add_10 = first(10)
add_10(2) returns 12
Bitwise operations
Bitwise operations are usually easier to CPU.
NOT
011 (3)
NOT 3 = 4 (100)
AND
011 (3) AND 100 (4) = 0 (000)
OR
011 (3) OR 100 (4) = 7 (111)