Memprogram 24LC64 dengan Port Serial

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace _24LC64
{
    /// 
<summary>
    /// Pin 3 (TX)  --          -- CS
    /// pin 4 (DTR) -- SCL      -- SCK
    /// Pin 6 (DSR) -- SDA IN   -- 
    /// Pin 7 (RTS) -- SDA OUT  -- MOSI (DO)
    /// Pin 8 (CTS) --          -- MISO (DI)
    /// </summary>


    public partial class Form1 : Form
    {
        public const bool H = true, L = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            serialPort1.BaudRate = 9600;
            serialPort1.PortName = textBox1.Text;
            serialPort1.Open();

            //serialPort1.DtrEnable = true;
            //serialPort1.RtsEnable = true;

            //perintah Write
            StartBit();
            kirim(0xA0);
            bit(1); //ACK
            
            //Alamat memory (0x001)
            //0x00 
            kirim(0x00);
            bit(1); //ACK
            //0x01
            kirim(0x01);
            bit(1); //ACK

            //Data (0x33)
            //kirim(0x33);
            byte[] data = StringToByteArray(textBox2.Text);
            kirim(data[0]);
            bit(1); //ACK
            
            StopBit();


            serialPort1.Close();

        }
        void kirim(int byteData) {
            for (int i = 7; i >= 0; i--) 
            {
                int bitData = (byteData >> i & 0x01);
                bit(bitData);
            }
        }
        void StartBit()
        {
            SDA(H); SCL(H);
            Thread.Sleep(1);
            SDA(L); SCL(H);
            Thread.Sleep(1);
        }
        void StopBit()
        {
            SDA(L); SCL(H);
            Thread.Sleep(1);
            SDA(H); SCL(H);
            Thread.Sleep(1);
        }
        void bit(int val) 
        {
            SCL(L);
            if (val == 0) SDA(L);
            else SDA(H);
            SCL(H);
            Thread.Sleep(1);
            SCL(L);
            SDA(H);
            Thread.Sleep(1);
        }

        void SCL(bool status)
        {
            serialPort1.DtrEnable = status;
        }
        void SDA(bool status)
        {
            serialPort1.RtsEnable = status;
        }

        int bacaBit() {
            int bitData = 0;
            SCL(L);
            SCL(H);
            bool bit = serialPort1.DsrHolding;
            if (bit == true) bitData = 1;
            Thread.Sleep(1);
            SCL(L);
            SDA(H);
            Thread.Sleep(1);
            return bitData;
        }

        public static byte[] StringToByteArray(string hex)
        {
            return Enumerable.Range(0, hex.Length)
                             .Where(x => x % 2 == 0)
                             .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                             .ToArray();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            serialPort1.BaudRate = 9600;
            serialPort1.PortName = textBox1.Text;
            serialPort1.Open();


            //perintah Write
            StartBit();
            kirim(0xA0);
            bit(1); //ACK

            //Alamat memory (0x001)
            //0x00 
            kirim(0x00);
            bit(1); //ACK
            //0x01
            kirim(0x01);
            bit(1); //ACK

            //perintah Read
            kirim(0xA1);
            bit(1); //ACK


            int data = 0;
            for (int i = 7; i >= 0; i--)
            {
                data = data << 1;
                data = data | bacaBit();
            }
            bit(1); //ACK

            StopBit();


            serialPort1.Close();
            byte[] hasil = new byte[1]; hasil[0] = (byte)data;
            textBox2.Text = BitConverter.ToString(hasil);
        }
    }
}

Menngunakan SyntaxHighlighter

Contoh penggunaan SyntaxHighlighter

[ cpp highlight="1,2,10-12" title="test.cpp"]

#include <OneWire.h>
#include <EEPROM.h>

#define DEBUG 1

OneWire ds(A1); // This is where DQ of your DS18B20 will connect.
bool validity = false;
void setup(void) {

#ifdef DEBUG
Serial.begin(9600);
#endif

validity = getDeviceAddress();
}
[/cpp]
#include <OneWire.h>
#include <EEPROM.h>

#define DEBUG 1

OneWire  ds(A1);  // This is where DQ of your DS18B20 will connect.
bool validity = false;
void setup(void) {

#ifdef DEBUG
  Serial.begin(9600);
#endif

  validity = getDeviceAddress();
}

Bahasa pemgrograman yang didukung:

actionscript3
bash
clojure
coldfusion
cpp
csharp
css
delphi
diff
erlang
fsharp
groovy
html
java
javafx
javascript
latex (tidak dapat untuk shortcode)
matlab (keywords saja)
objc
perl
php
powershell
python
r (tidak dapat untuk shortcode)
ruby
scala
sql
text
vb
xml

Proteksi firmware ATmega dengan Nomor Seri

Menggunakan bantuan 1-Wire device, dengan jenis yang bermacam macam, misal: DS1820

#include <OneWire.h>
#include <EEPROM.h>

#define DEBUG 1

OneWire  ds(A1);  // This is where DQ of your DS18B20 will connect.
bool validity = false;
void setup(void) {

#ifdef DEBUG
  Serial.begin(9600);
#endif

  validity = getDeviceAddress();
}

bool getDeviceAddress(void) {
  byte i;
  byte addr[8];
  bool valid = false;

  unsigned long upper = 0;
  unsigned long lower = 0;

#ifdef DEBUG
  Serial.println("Getting serial number...\n\r");
#endif
  while (ds.search(addr)) {
    if ( OneWire::crc8( addr, 7) != addr[7]) {
#ifdef DEBUG
      Serial.print("CRC is not valid!\n");
#endif
      return;
    }

    for (byte i = 0; i < 4; i++) {
      upper = upper << 8;
      upper = upper | addr[i];
    }
    for (byte i = 4; i < 8; i++) {
      lower = lower << 8;
      lower = lower | addr[i];
    }

    unsigned long result = upper & lower;
    Serial.println(result);

    bool initsn = false;
    if (EEPROM.read(0) == 0xFF) initsn = true;

    //initsn=true;
#ifdef DEBUG
    if (!initsn) Serial.println("Checking serial number...\n\r");
    else Serial.println("Writing serial number...\n\r");
#endif

    valid = true;
    for (byte i = 0; i < 4; i++) {
      byte e = EEPROM.read(i + 1);
      byte r = result & 0xff;
      if (initsn)
        EEPROM.write(i + 1, r);
      if (e != r) valid = false;
      result = result >> 8;
    }
    if (initsn) EEPROM.write(0, addr[7]);

#ifdef DEBUG
    if (valid) Serial.println("Good serial number...\n\r");
    else Serial.println("Bad serial number...\n\r");
#endif

  }
  ds.reset_search();
  return valid;
}


void loop(void) {
  // do nothing
}

Mengubah USB ISP menjadi USBASP

USBISP berbeda dengan USBASP. USBISP tidak dapat dioperasikan dengan AVRDude, namun harus menggunakan PROG ISP. USB ISP menggunakan uC ATmega88, dengan skema mirim USBASP namun bedanya adalah pin D- pada USB dihubungkan ke PD3, jadi PD3 harus diubah menjadi pin INPUT.

Agar dapat berfungsi jadi USBASP, maka download firmware dari https://www.fischl.de/usbasp/usbasp.2011-05-28.tar.gz dan ekstrak.

Buka file bin/usbasp.atmega88.2011-05-28.hex menggunakan notepad++ atau wordpad.

Lihat pada baris 100B8000,

:100B8000D9F77A9589F708951BB815B88BEF8AB90C

ubah menjadi :

:100B8000D9F77A9589F708951BB815B880EF8AB917

ubah ldi pada DDRD 8BEF menjadi  80EF

dan ubah checksum dari  0C  menjadi  17

Buka kemasan USBISP dan hubungkan via (lubang) yang ditandai <– UP –> menggunakan kabel kecil.

Upload dengan USBASP atau Arduino yang telah dijadikan Arduino as ISP.

Note:

# TARGET=atmega8 HFUSE=0xc9 LFUSE=0xef
# TARGET=atmega48 HFUSE=0xdd LFUSE=0xff
# TARGET=atmega88 HFUSE=0xdd LFUSE=0xff

gunakan HEX berikut, jika uC yang digunakan adalah ATmega8:

:100000003BC09FC554C053C052C051C050C04FC028
:100010004EC04DC04CC04BC04AC049C048C047C08C
:1000200046C045C044C0040309041C0377007700A0
:1000300077002E00660069007300630068006C00A2
:100040002E00640065000E0355005300420061005D
:100050007300700012011001FF000008C016DC05DB
:1000600003010102000109021200010100801909C7
:10007000040000000000000011241FBECFE5D4E002
:10008000DEBFCDBF10E0A0E6B0E0E0EAFDE002C0D8
:1000900005900D92A236B107D9F710E0A2E6B0E0C4
:1000A00001C01D92A73AB107E1F702D077C6A8CFE9
:1000B00012BA18BA11BA8FEF87BB17BA93E094BB84
:1000C0008EEF85BB93BF08D478940DD4FECFFF92FA
:1000D0000F931F93CF93DF939C01F62E80916200C4
:1000E000813021F4E90110E000E078C08430D1F3E0
:1000F0001FEF77C080916200813079F580917300A5
:100100009091740020916F003091700040917100C7
:1001100050917200892B31F4CA01B901488121E064
:1001200088D321C0CA01B901488120E082D38091DF
:1001300076008150809376008823A9F460916F0047
:10014000709170008091710090917200488126D367
:10015000809173008093760006C080916F0090912B
:1001600070006881F7D280916300909164000197DC
:100170009093640080936300892BD9F410926200FD
:100180008091750081FF14C08091760090E02091ED
:100190007300309174008217930751F060916F00E3
:1001A0007091700080917100909172004881F6D238
:1001B00011E080916F0090917000A0917100B0915A
:1001C00072000196A11DB11D80936F009093700085
:1001D000A0937100B09372000F5F21960F1508F481
:1001E00089CF812FDF91CF911F910F91FF900895BB
:1001F0000F931F93CF93DF939C01062F8091620092
:100200008250823010F00FEF32C0E90110E029C0B7
:1002100080916200823051F460916F0070917000A3
:10022000809171009091720043D205C080916F005F
:100230009091700071D2888380916F0090917000CE
:10024000A0917100B09172000196A11DB11D809323
:100250006F0090937000A0937100B09372001F5FC5
:1002600021961017A8F2083010F410926200802F27
:10027000DF91CF911F910F910895CF93DF93EC0100
:100280008981813061F49A9902C085E002C0809131
:1002900065001FD110926600A99879D104C0823000
:1002A00021F496D1A99A20E0F7C0833011F5E091AE
:1002B0007800F09179008A81099580936700E09138
:1002C0007800F09179008B81099580936800E09126
:1002D0007800F09179008C81099580936900E09114
:1002E0007800F09179008D81099580936A0024E06F
:1002F000D3C0843011F580916600882391F49B81EE
:1003000080E02A8130E0822B932BAA2797FDA095CD
:10031000BA2F80936F0090937000A0937100B093F8
:1003200072009F8180E02E8130E0822B932B90938E
:1003300064008093630082E090C0873011F5809163
:100340006600882391F49B8180E02A8130E0822B33
:10035000932BAA2797FDA095BA2F80936F009093B7
:100360007000A0937100B09372009F8180E02E8195
:1003700030E0822B932B909364008093630083E0A2
:100380006CC0853021F451D18093670084C08630E1
:10039000D9F580916600882391F49B8180E02A81C1
:1003A00030E0822B932BAA2797FDA095BA2F80933C
:1003B0006F0090937000A0937100B09372008C81D5
:1003C0009D81292F2F7020937500492F50E0407F89
:1003D000507094E0440F551F9A95E1F7480F511D56
:1003E000509374004093730020FF02C04093760046
:1003F0009F8180E02E8130E0822B932B90936400CC
:100400008093630081E029C0883059F580916600AF
:10041000882391F49B8180E02A8130E0822B932B0A
:10042000AA2797FDA095BA2F80936F009093700034
:10043000A0937100B0937200109274001092730038
:10044000109275009F8180E02E8130E0822B932BEB
:10045000909364008093630084E0809362002FEFA8
:100460001BC0893081F481E0809366008A819B8182
:10047000AC81BD8180936F0090937000A093710058
:10048000B093720010CF8A3009F00DCF8A8180932B
:1004900065001092670021E087E690E090938C0061
:1004A00080938B00822FDF91CF910895382F90E0B9
:1004B00006C022B782B7821B8C33E0F39F5F93178D
:1004C000C0F3089580917B008DB980917A008EB938
:1004D0000895282F882311F42AE002C0883028F1DB
:1004E00080E193E0909379008093780010927A00F5
:1004F0002930A9F02A3018F4283051F412C02B30DA
:1005000029F02C3029F481E080937A0081E50AC03B
:1005100082E580937B0081E080937A00089582E5F4
:1005200001C083E580937B00089580EF92E0909373
:100530007900809378002430B1F0253038F42230EF
:10054000B1F0233090F42130C9F415C0263031F0D9
:10055000263038F0273091F483E00AC020937C00E5
:1005600008958CE005C088E103C080E301C080E607
:1005700080937C00089580EC80937C00089522B7DE
:1005800090917C0082B7821B8917E0F3089587B3AE
:100590008C6287BBC298C59892B720917C0082B7C5
:1005A000891B8217E0F3C29A92B782B7891B821720
:1005B000E0F3C29880917800909179008051934047
:1005C00031F480917B008DB980917A008EB90895C5
:1005D00087B3837D87BB88B3837D88BB1DB80895AF
:1005E000482F50917C0020E030E047FF02C0C39AC2
:1005F00001C0C398220FB4992F5FC59A92B782B7F2
:10060000891B8517E0F3C59892B782B7891B8517B8
:10061000E0F33F5F383011F0440FE7CF822F0895A9
:100620008FB9779BFECF8FB108950F931F9300E290
:1006300039C0E0917800F09179008CEA0995E09159
:100640007800F091790083E50995E0917800F091C8
:10065000790080E00995182FE0917800F0917900F9
:1006600080E00995133511F480E01FC01DB8C59ACC
:1006700092B720917C0082B7891B8217E0F3C5985E
:1006800092B782B7891B8217E0F38091780090912E
:1006900079008051934031F480917B008DB9809135
:1006A0007A008EB9015028F681E01F910F910895CC
:1006B000EF92FF920F931F937B018C01862F817025
:1006C000880F880F880FE0917800F09179008062A0
:1006D0000995D801C70129E0B695A7959795879503
:1006E0002A95D1F7E0917800F09179000995169557
:1006F0000795F794E794E0917800F09179008E2DBA
:100700000995E0917800F091790080E009951F91BA
:100710000F91FF90EF9008950F931F938C01E0913C
:100720007800F091790080EA0995E0917800F091E5
:100730007900812F0995E0917800F0917900802F60
:100740000995E0917800F091790080E009951F917A
:100750000F910895FF920F931F938C01F62EE09155
:100760007800F091790080EC0995E0917800F091A3
:100770007900812F0995E0917800F0917900802F20
:100780000995E0917800F09179008F2D09958EE11F
:100790008DDE80E01F910F91FF900895CF92DF9240
:1007A000EF92FF920F931F936B017C01142FE09146
:1007B0007800F09179008CE40995D701C60149E0F1
:1007C000B695A795979587954A95D1F7E0917800CA
:1007D000F09179000995D701C601B695A79597952F
:1007E0008795E0917800F09179000995E091780083
:1007F000F091790080E009951F3F19F48FE056DEF3
:1008000007C002B71EE1C701B60152DF8F3F11F0EA
:1008100080E008C082B7801B8D33A8F302B7115067
:1008200091F781E01F910F91FF90EF90DF90CF90B3
:100830000895CF92DF92EF92FF920F931F936B0177
:100840007C01042F122F862F8170880F880F880F4C
:10085000E0917800F091790080640995D701C60194
:1008600069E0B695A795979587956A95D1F7E09138
:100870007800F09179000995D701C601B695A79542
:1008800097958795E0917800F09179000995E0912E
:100890007800F0917900802F09951123A9F00F3786
:1008A00019F48FE003DE10C002B71EE1C701B601E4
:1008B000FFDE8F3749F482B7801B8D33B8F302B760
:1008C0001150A1F781E001C080E01F910F91FF90CE
:1008D000EF90DF90CF90089585B7836085BF8BB789
:1008E00080648BBF08951F93CF93DF9360918D0039
:1008F000635067FDA3C080918A00CCE0D0E0C81BA4
:10090000D109CF56DF4F809189008D3209F084C024
:10091000683009F091C083EC80937D008AE5809374
:100920006000109277008881807639F0CE01A5DCD6
:10093000282F8F3F09F45FC065C09A81109286000E
:100940008981882321F41092870022E04DC08530F0
:1009500019F490938E0047C08630B1F58B818130B9
:1009600019F484E590E004C0823041F486E690E01A
:1009700090938C0080938B0022E122C08330F9F4A5
:100980008A81882341F486E290E090938C008093E2
:100990008B0024E015C0813041F48AE290E090930E
:1009A0008C0080938B002CE10BC0823041F486E4F4
:1009B00090E090938C0080938B002EE001C020E0AB
:1009C00080E4809377001EC0883021F421E080E924
:1009D00090E00CC0893019F49093900004C08A30E4
:1009E00011F421E001C020E086E890E090938C00B3
:1009F00080938B0007C0888187FD2E8180E88093DB
:100A0000770006C08F81882319F48E81821708F041
:100A1000822F8093610010C08091770087FF0CC007
:100A2000CE0155DB8F3F21F48EE18093600004C03E
:100A3000882311F01092610010928D008091600067
:100A400084FF58C0809161008F3F09F453C0182F74
:100A5000893008F018E0811B8093610080917D004F
:100A600098E8892780937D00112391F18091770088
:100A700087FF08C08EE790E0612FBADB182F89301E
:100A800098F526C020918B0030918C0086FF0DC018
:100A9000AEE7B0E080E090E0F901E80FF91FE491E3
:100AA000ED9301961817C1F708C0912FD901EEE711
:100AB000F0E08D9181939150E1F71150812F90E0FA
:100AC0001F5F0196820F931F90938C0080938B0081
:100AD0008EE790E0612F31D0612F6C5F6C3041F078
:100AE0008FEF8093610004C08FEF809361006EE10F
:100AF0006093600094E186B3837031F49150D9F72C
:100B000010928E0010928800DF91CF911F9108956E
:100B1000A82FB92F80E090E041E050EA60956F5F28
:100B200058F42D9138EF82279795879510F08427F8
:100B300095273F5FC8F3F3CF0895EADF8D939D9328
:100B40000895CF93CFB7CF93C395B09BE9F7B09BF0
:100B500009C0B09B07C0B09B05C0B09B03C0B09B51
:100B600001C0A1C0DF93C0918A00DD27CF56DF4FBF
:100B7000B09B02C0DF91EBCF2F930F931F9306B36F
:100B80002FEF00FB20F94F933F9316B34FEF012750
:100B900000FB21F93BE031C04E7F012F16B32160ED
:100BA00028C0102F4D7F2260000006B329C04B7F64
:100BB0002460012F000016B32BC016B3477F2860B6
:100BC0002AC04F7E06B320612CC04F7D16B3206231
:100BD0002FC04F7B06B3206432C0422706B349932F
:100BE0004FEF0000102710FB20F916B31370C9F166
:100BF000297F91F2012700FB21F906B3237F89F2B7
:100C0000315058F1102710FB22F916B3277E79F2E4
:100C1000012700FB23F92F7C81F206B3102710FB7C
:100C200024F92F7971F200C016B3012700FB25F9D2
:100C30002F7359F200C006B3102710FB26F922309B
:100C400040F200C016B3012700FB27F9243028F634
:100C50004F77206816B30000F9CF10E41ABF0027C1
:100C600017C03B503195C31BD04010E41ABF088118
:100C7000033CE9F00B34D9F0209188001981110F61
:100C80001213EDCF093641F10D3211F0013E39F763
:100C900000938F003F914F911F910F912F91DF9102
:100CA000CAB7C6FD51CFCF91CFBFCF911895209134
:100CB0008F00222379F310918D00112311F5343028
:100CC00012F130938D002093890010918A003BE04F
:100CD000311B30938A0017C000918D0001308CF4D5
:100CE0000AE53091600034FD10C000936000CDE74C
:100CF000D0E00FC02795A8F45150A9F4220F0000AE
:100D0000F9CF4AE503C042ED01C0432FC4E1D0E072
:100D100032E017B31360C09A17BB08B320E413E0A6
:100D20005F93012756E008BB279520F4515021F42A
:100D3000220FF9CF012756E000003B5A08BBD0F242
:100D4000279528F4515029F4220F0000F9CF0127EC
:100D500056E0279508BB20F4515021F4220FF9CF1B
:100D6000012756E02991332308BB21F60C7F10910F
:100D70008E00110FC651D04008BB11F010938800AF
:100D800010E41ABF016017B31C7F402F4C7F5F91A6
:100D900000C000C008BB17BB48BB7CCFF894FFCF96
:020DA0005AFFF8
:00000001FF

Menambahkan Bootloader ATMega8 di Arduino versi 1.5.x ke atas

buka file platforms.txt

cari bagian: tools.avrdude

copy paste barisnya dan ubah menjadi tools.avrdudeM8 dengan menghapus -Uefuse:w:{bootloader.extended_fuses}:m

# AVR Uploader/Programmers tools M8
# ------------------------------

tools.avrdudeM8.cmd.path={runtime.ide.path}/hardware/tools/avr/bin/avrdude
tools.avrdudeM8.config.path={runtime.ide.path}/hardware/tools/avr/etc/avrdude.conf

tools.avrdudeM8.upload.params.verbose=-v -v -v -v
tools.avrdudeM8.upload.params.quiet=-q -q
tools.avrdudeM8.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"

tools.avrdudeM8.program.params.verbose=-v -v -v -v
tools.avrdudeM8.program.params.quiet=-q -q
tools.avrdudeM8.program.pattern="{cmd.path}" "-C{config.path}" {program.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{build.path}/{build.project_name}.hex:i"

tools.avrdudeM8.erase.params.verbose=-v -v -v -v
tools.avrdudeM8.erase.params.quiet=-q -q
tools.avrdudeM8.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Ulock:w:{bootloader.unlock_bits}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m

tools.avrdudeM8.bootloader.params.verbose=-v -v -v -v
tools.avrdudeM8.bootloader.params.quiet=-q -q
tools.avrdudeM8.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params} "-Uflash:w:{runtime.platform.path}/bootloaders/{bootloader.file}:i" -Ulock:w:{bootloader.lock_bits}:m

Buka Board.txt, cari atmegang.menu.cpu.atmega8=ATmega8 dan tambahkan diatasnya:

 

atmegang.menu.cpu.atmega8.bootloader.tool=avrdudeM8

Selanjutnya pilih Board: ArduinoNG, Processor: ATmega8, Programmer: (sesuaikan)

Siap untuk klik, Burn Bootloader

Mengubah script python menjadi executable

Menggunakan Linux

Gunakan pyinstaller, pasang dengan:

pip install pyinstaller

Jika gagal, maka:

Buka: https://github.com/pyinstaller/pyinstaller/releases
Download: PyInstaller-3.3.1.tar.gz lalu extract dan masuk kedirektori tersebut.
Eksekusi dengan perintah:

sudo python setup.py build 
sudo python setup.py install

Selanjutnya ubah script python ke executable dengan

pyinstaller --onefile <script_phyton>.py

Jika dikatakan bootloader belum tersedia, misalnya untuk Linux ARM 32Bbit, maka harus dibuat dahulu. Pada hasil download PyInstaller ada direktori bootloader. Masuk ke direktori tersebut dan jalankan perintah:

sudo python ./waf all
cd ../PyInstaller/bootloader
cp -R Linux-32bit-arm/ /home/pi/.local/lib/python2.7/site-packages/PyInstaller/bootloader/Linux-32bit-arm/
 

sumber: https://pyinstaller.readthedocs.io/en/stable/bootloader-building.html

Menerima paket UDP dan meneruskan ke URL atau website

Gunakan script phyton ini:

import socket, urllib2

UDP_IP = "127.0.0.1"
UDP_PORT = 50000

sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
#sock.bind((UDP_IP, UDP_PORT))
sock.bind(("", UDP_PORT)) #bind, receive from any addresss

while True:
 data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
 print "received message:", data
 stringdata = str(data)
 if stringdata[0] == "+":
 value = stringdata[2]
 karakter = ord(loket)
 karakter = karakter + 1;
 value = chr(karakter)
 url = "http://localhost/getUDP.php?var="+value
 print "url:", url
 response = urllib2.urlopen(url)
 headers = response.info()
 data = response.read()
 print data

Menambahkan autorun pada linux raspberry

buka direktori ~/config/autostart, buat jika belum ada dengan mkdir

buat file berektensi .desktop, misalnya chrome.desktop

lalu isikan script berikut

[Desktop Entry]
Type=Application
Name=Clock
[Desktop Entry]
Type=Application
Name=Clock
Exec=chromium-browser --kiosk --app=http://localhost/

Chrome akan berjalan setelah GUI terbuka, fullscreen tanpa notifikasi dengan sempurna. Namun jika ingin autorun saat booting, maka gunakan cara berikut:

sudo leafpad /etc/rc.local

sebelum bagian  exit 0 tambahkan kode berikut:

python /home/pi/blink.py &

Penting: Ampersand (&) dibutuhkan agar proses autorun tidak memblokir proses yang lain, dangan kata lain proses yang lain juga akan terbuka walaupun proses autorun ini belum sepenuhnya selesai. Jika tanpa tanda ampersand, maka proses autorun ini akan ditunggu hingga selesai baru proses lain dibuka. Akan menjadi masalah jika pada proses ini loop, maka tidak akan pernah bisa login.

Untuk menghentikan proses loop pada autorun, gunakan:

sudo ps -ax | grep python
sudo kill <PID>

ganti <PID> dengan nomor proses. Hati hati jangan keliru, komputer bisa hang!

sumber: https://learn.sparkfun.com/tutorials/how-to-run-a-raspberry-pi-program-on-startup/all

Autoplay Video pada HTML

bagian html, isikan:

<html>
<head>Video playlist</head>
<body>

<video autoplay id="myVideo" width="480" height="326" style="object-fit: fill;">
Browser tidak mendukung video
</video>

<script src='video/list.php'></script>

<script type="text/javascript">
var videoSource = new Array();
for(var x=0; x<=files.length; x++){
    videoSource[x]='http://localhost/antrian/video/'+files[x]+'.mp4';
}

var videoCount = videoSource.length;

document.getElementById("myVideo").setAttribute("src",videoSource[0]);

function videoPlay(videoNum)
{
    document.getElementById("myVideo").setAttribute("src",videoSource[videoNum]);
    document.getElementById("myVideo").load();
    document.getElementById("myVideo").play();
}

document.getElementById('myVideo').addEventListener('ended',myHandler,false);

var i=0;
function myHandler() {
    i++;
    if(i == (videoCount-1)){
        i = 0;
        videoPlay(i);
    }else{
        videoPlay(i);
    }
}

</body>
</html>

lalu buat file list.php pada direktory video, dengan mengisikan script berikut:

var files = <?php $out = array();
foreach (glob('*.mp4') as $filename) {
$p = pathinfo($filename);
$out[] = $p['filename'];
}
echo json_encode($out); ?>;

selanjutnya taruh file video dengan format mp4 ke direktori video