Tuesday, May 28, 2019

Arduino Serial Data LED Control

Arduino Serial Data LED Control

Arduino is great platform for prototyping and commercial projects.its even worthy because it support easy serial communication between PC and Arduino Board.this capability can be used to communication between PC Desktop Application and a Arduino Board Control.

Here's a small Sketch that read serial data and do stuff accordingly.



byte LED = 13;

void setup() {
  Serial.begin(9600);
  delay(100);
  pinMode(LED, OUTPUT);
}

void loop() {
  if (Serial.available()) {
    char inChar = (char)Serial.read();
    if (inChar == '\r' || inChar == '\n') {
    } else {
      if (inChar == '1') {
        digitalWrite(LED, HIGH);
      } else {
        digitalWrite(LED, LOW);
      }
    }
  }
}

When  character 1 is written to the serial data stream, the led connected to the pin 13 will light up.
any other character will turn it off.

in action : https://youtu.be/6N7fr1qJ5oA

github : https://github.com/stark9000/Arduino-Serial-Data-LED-Control



Sunday, May 5, 2019

java swing undecorated moveable jframe form

 java swing undecorated moveable jframe form 


Ever since i have seen a key-gen , i was curious about how to make one in java.this is some of the progress along the way, the moveable yet no window controllers and play pause chip-tune music with transparent background.so far i have accomplished my task.
 

 AWTUtilities.setWindowOpacity(this, 0.8f); <- this is line responsible for windows transparency level.
 AWTUtilities.setWindowOpaque(this, false); <- this line is for controlling frames backgroung opaqe


moving the undecorated frame

private void CaptureMove() {
        this.addMouseMotionListener(new MouseMotionAdapter() {

            @Override
            public void mouseDragged(MouseEvent event) {
                try {
                    Point point_location = event.getPoint();

                    if (DRAG_START == null) {
                        DRAG_START = point_location;
                    }
                    CURRUNT_LOCATION = point_location;

                    Point location = getLocation();
                    setLocation(location.x + (CURRUNT_LOCATION.x - DRAG_START.x),
                            location.y + (CURRUNT_LOCATION.y - DRAG_START.y));
                } catch (Exception e) {
                }
            }
        });
        this.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseReleased(MouseEvent event) {
                try {
                    Point point_location = getLocation();
                    setLocation(point_location.x + (CURRUNT_LOCATION.x - DRAG_START.x),
                            point_location.y + (CURRUNT_LOCATION.y - DRAG_START.y));
                    DRAG_START = null;
                } catch (Exception e) {
                }
            }
        });

    }

playing the chip-tune
private synchronized void play() {
        if (ibxm != null) {
            playing = true;
            playThread = new Thread(new Runnable() {

                @Override
                public void run() {
                    int[] mixBuf = new int[ibxm.getMixBufferLength()];
                    byte[] outBuf = new byte[mixBuf.length * 4];
                    AudioFormat audioFormat = null;
                    SourceDataLine audioLine = null;
                    try {
                        audioFormat = new AudioFormat(SAMPLE_RATE, 16, 2, true, true);
                        audioLine = AudioSystem.getSourceDataLine(audioFormat);
                        audioLine.open();
                        audioLine.start();
                        while (playing) {
                            int count = getAudio(mixBuf);
                            int outIdx = 0;
                            for (int mixIdx = 0, mixEnd = count * 2; mixIdx < mixEnd; mixIdx++) {
                                int ampl = mixBuf[mixIdx];
                                if (ampl > 32767) {
                                    ampl = 32767;
                                }
                                if (ampl < -32768) {
                                    ampl = -32768;
                                }
                                outBuf[outIdx++] = (byte) (ampl >> 8);
                                outBuf[outIdx++] = (byte) ampl;
                            }
                            audioLine.write(outBuf, 0, outIdx);
                        }
                        audioLine.drain();
                    } catch (Exception e) {
                    } finally {
                        if (audioLine != null && audioLine.isOpen()) {
                            audioLine.close();
                        }
                    }
                }
            });
            playThread.start();
            Play.setText("||");
        }
    }



  public void LoadMoDFile() {
        String path = System.getProperty("user.dir") + System.getProperty("file.separator") + "cptun.xmfile";
        File ff = new File(path);
        try {
            loadModule(ff);
        } catch (IOException ex) {
            System.out.println("" + ex);
        }
    }



    private synchronized void loadModule(File modFile) throws IOException {
        byte[] moduleData = new byte[(int) modFile.length()];
        FileInputStream inputStream = new FileInputStream(modFile);
        int offset = 0;
        while (offset < moduleData.length) {
            int len = inputStream.read(moduleData, offset, moduleData.length - offset);
            if (len < 0) {
                throw new IOException("Unexpected end of file.");
            }
            offset += len;
        }
        inputStream.close();
        module = new Module(moduleData);
        ibxm = new IBXM(module, SAMPLE_RATE);
    }

American corner - Maker Fair 2018 Kandy Mini Engineering Exhibition

Maker Fair 2018 Kandy Mini Engineering Exhibition 

In 2018 December American corner Kandy maker space club organized a mini engineering exhibition for tech enthusiasts and public including school children's.i have involved in maker space public seminar series in Sundays.lately i had the chance to join the exhibition organizing committee.after three weeks of time, we success fully held the exhibition at American corner Kandy.below are some pictures.












this is been a big event  for Kandy.

scratch engraver

scratch engraver

Since auto level didn't worked for me i thought to make a scratch engraver tool.that will automatically adjust the heights and pressure according to PCB copper board surface.to make this work first i have to paint copper clad boards surface with marker pen.then i have used a iron nail as a engraving bit.i have built a tube that have the diameter of the original spindle.then i used the chilipeppr to run the machine.

below is the result :

i'm planing to improve my idea with spring loaded tool.

2020B CNC with Arduino CNC shield

2020B CNC with Arduino CNC shield 

After all those in-accurate cnc builds i have decided to buy a cnc. so i bought a 2020b cnc machine from local market.sellers didn't know about any technical parameters or software or even how to assemble this together.i received a dvd which contained some instructions but not very clear.in there there is was a software called  " CNC USB Controller " which seems to bee too old.after little googling i have decided to convert this to grbl. so i started adding limit switches.then i installed the Arduino cnc shield and uploaded grbl firmware.then i have adjust few settings of the firmware.i choose UGS software as PC side control software.



lately i have discovered " http://chilipeppr.com/grbl " is great online too for controlling cnc machines.
its so great that it even convert eagle cad pcb layout brd files to gcode without any other software.
to use this you need a internet connection and json serial sever installed.to me auto leveling didn't went well.but other functions worked correctly.

Friday, May 3, 2019

DIY CNC Machines

DIY CNC Machines 

 This is about all the DIY cnc machines i have built from scratch.i have builed many of them using arduino platform.but after making them i have noticed accuracy is not so good due to metirials i have use to build them.dvd motors consumes lot of power.it needed to powered from external source of power which is capable of providing 3-4apms to the motors else motors won't work they will start to humming due to lack of power.i have used easy driver 1.3 module to drive the steppers.of course i have used the Arduino UNO as the mother board.there is a lot of arduino sketches in the internet that uses Arduino and processing to connect the machine to pc.ink-scape is the software used in many of this kind of machines to generate g codes.

In these setup its lot of work to be done on the software and it didn't feels like complete setup.it kind a feels like in experiment level of thing.so i moved to the Arduino cnc-shield grbl.this way its easy to use and feels complete as well. so the second machine first used uln 2008 drivers.i switched away from them and settled for cnc-shield.i had to convert 28byj-48moters to be bipolar in order to connect them to cnc-shield. this far i have learned lot about cnc machines.so i ordered some stuff from ebay and start building a big machine. i was able to find 17pm-h005-p2va from  old dot matrix printers.i used them in the big machine.




dvd motor based mini-cnc 28byj-48


this one use 28byj-48 stepper motors that modded to be a bipolar.






this one use three 17pm-h005-p2va stepper motors from old dot-matrix printers.

















After all the grbl and cnc shield is good choice.but the materials i have choose to build the hardware is not so.i think aluminum is the greatest material to in this kind of thing.


DIY toroidal transformer

DIY toroidal transformer

When i first heard about toroid transformers its all about efficiency and great characteristics so i wanted to make one my self .but to find a core is not easy in our city had to wait for a long time in searching for a one.then i found few. i have re-winded 2 of them successfully.and had the chance to build a one for my personal use. as i advanced the ladder of toroid winding i have met some expertise, so i learned from them and i even made a calculation software as well.





lately i have found some you-tube channels, show how to about the topic :

https://www.youtube.com/watch?v=_1HlQ5Vb-ks

https://www.youtube.com/watch?v=nlmtKEl_7gM



wesak lanterns

wesak lanterns

Wesak is a Buddhist ceremony to celebrate lord Buddhas birth, become Buddha,  parinirwanaya.
to celebrate this people make lanterns, candles, lights, lighting decorations,songs and lot of things related to the religious view.in the earl days we make lanterns using bamboo then people start to make them with iron rods for longer life, and re-usability. after some time people discovered a way to make them with straw tubes that are used in drinking drinks.so i tried this technique and i got successful. and i made lot of lanterns in little time i even made some complicated patterned lanterns as well.


below lantern are made from bamboo.



 

below ones are made from straw tubes.
















































it only takes few minutes to built the skeleton but takes considerable amount of time to decorate it with oil papers.