Dec 19, 2020

 still under development for arduino grbl

Drivers and how to connect to arduino in the next video. I will keep the driver in the cloud Software Robodk https://robodk.com/ Create a 6-axis Robot Arm: https://youtu.be/fNdqvi81djM RoboDK Arduino GRBL - Robot GRBL for Robodk: https://youtu.be/YV8CytL1IdE
SHOW LESS

Dec 6, 2020

CNC

 Grbl Mega 5Axis 



Dec 3, 2020

Support me for more videos: https://www.patreon.com/GreatScott Previous video: https://youtu.be/r9GMUYa_DvY Arduino Basics 101: https://youtu.be/BtLwoNJ6klE Facebook: https://www.facebook.com/greatscottlab Twitter: https://twitter.com/GreatScottLab You can get Arduino boards here (affiliate links): Aliexpress: Arduino Uno: https://s.click.aliexpress.com/e/_dT2... Arduino Nano: https://s.click.aliexpress.com/e/_dUL... Arduino Pro Mini: https://s.click.aliexpress.com/e/_d62... FTDI board: https://s.click.aliexpress.com/e/_dV4... Ebay: Arduino Uno: http://rover.ebay.com/rover/1/711-532... Arduino Nano: http://rover.ebay.com/rover/1/711-532... Arduino Pro Mini: http://rover.ebay.com/rover/1/711-532... FTDI board: http://rover.ebay.com/rover/1/711-532... Amazon.de: Arduino Uno: http://amzn.to/2ljDLFL Arduino Nano: http://amzn.to/2ljnq3J Arduino Pro Mini: http://amzn.to/2kMv0ly FTDI board: http://amzn.to/2ljvuRY In this second epsiode of the Arduino Basics video series I will talk about control structures like if, for, while and switch and how to use them in combination with variables to create more advanced code. At the end I will also talk about why interrupts are so important and how to use them as well. Music: In the Hall of the Mountain King, Kevin MacLeod Ecstatic Wave, Jens Kiilstofte https://machinimasound.com/music
SHOW LESS

This repository is for those who would like to learn how to use the Python module PySerial and Arduino.

There will be a corresponding Arduino (.ino) and Python (.py) file for each part. Each part builds upon the previous.


View the YouTube Play List for step by step instruction and detailed instructions:

https://www.youtube.com/playlist?list=PLb1SYTph-GZJb1CFM7ioVY9XJYlPVUBQy

All code

 Code

saves = open('data.txt', 'w')

saves.write(path)

-----------------------------------------

def chooseDir(): 

global path

path = filedialog.askdirectory(title="Choose a download directory")

tk.Label(root, text=path, bg='gray').place(x=240,y=300)

saves()

---------------------------------------------------

saves = open('data.txt', 'w')

--------------------------------------------

tk_buttom

Button(root,text="Download video", width=20, bg='black',fg="white", command=downloadVideo).place(x=240, y=130)

Button(root,text="Choose location", width=20, bg='black',fg="white", command=chooseDir).place(x=240, y=160)

Label_3=Label(root, text="Curent location: ", font=("bold"), bg='gray')

Label_3.place(x=250, y=245)





Dec 1, 2020

Serial python

The response always ends with the FF byte. So i want to read the bytes into a buffer untill i encounter FF. Than the buffer should be printed and the function should return.

import serial

s_port = 'COM1'
b_rate = 2400

#method for reading incoming bytes on serial
def read_serial(ser):
    buf = ''
    while True:
        inp = ser.read(size=1) #read a byte
        print inp.encode("hex") #gives me the correct bytes, each on a newline
        buf = buf + inp #accumalate the response
        if 0xff == inp.encode("hex"): #if the incoming byte is 0xff
            print inp.encode("hex") # never here
            break
    return buf   

#open serial
ser = serial.Serial(
    port=s_port,
    baudrate=b_rate,
    timeout=0.1
)

while True:

    command = '\x05\x06\x40\x00\x02\x05\xF6\x5C' #should come from user input
    print "TX: "
    ser.write(command)
    rx = read_serial(ser) 

print "RX: " + str(rx) 

===============================================================

python serial read

วันนี้ได้เขียนหลายเรื่องเลย งานเร่งด่วนมาก
ตอนนี้จะเกี่ยวกับการอ่านค่า ที่ได้รับจาก serial port

ตัวอย่าง code

#! /usr/bin/python

 
import time
import serial

port = serial.Serial("/dev/ttyUSB0", baudrate=19200, timeout=1.0)

i = 1

while 1:
  port.write(chr(i))
  rcv = port.read(1) ================== (1)
  if rcv != '':================== (2)
    ans = ord(rcv) ================== (3)
    if ans == 0x61:
      print "Status Ready"
    else:
      print rcv
  else: ================== (4)
    print "Loss communication"


(1) คืออ่านค่าจาก serial port ใส่ในตัวแปร rcv
(2) ตรวจสอบว่าค่า rcv ที่อ่านมา มีค่าอะไรอยู่หรือไม่ ถ้ามีก็ทำต่อไป ถ้าไม่มีก็กระโดดไปที่ (4)
(3) เปลี่ยนตัวแปร rcv ที่เป็น string ให้เป็น int เพื่อที่เราจะสามารถเปรียบเทียบค่ากับ hex ที่เราต้องการได้


ที่มา http://stackoverflow.com/questions/12929593/how-to-test-for-hexidecimal-output-on-serial-port-in-python

=========================================================================

Python re

https://l.facebook.com/l.php?u=https%3A%2F%2Fmedium.com%2F%40tanabodin.kamol%2Fpython-regular-expression-8e8b87ee44a6%3Ffbclid%3DIwAR0oobY_M85uZVB_nLNPpSuHaCRGHZyHERZpaudtYQGM3n-yM9ZrwbK9KGc&h=AT1HL99ZYq1IkaBRNYOxmGLtRXpyw6cB4GrZ5B0_lBdeisOynBqZ9iecRYZmz-aDlbkmGAbx4s51Kb0zZ0JhLxisLHIwAhP3jAumk9F-A0xzbKYMNTNDxHg15eSlNgbj_B30nQ


========================================================================

Nov 27, 2020

send one gcode

How to send one gcode command over USB?


 I am trying to write a simple python script that sends a gcode command to my wanhao D9 motherboard printer, running Marlin. I am running the python script on a raspberry pi that is connected to the printer via USB.
import serial

ser = serial.Serial("/dev/ttyUSB0", 115200)
ser.write("G28\n")

I have read over 20 forum pages with simular problems and tried their answers such as changing the baud rate to 250000 and the following changes to the write function parameter:

ser.write("G28\r\n")
ser.write(b'G28\r\n')
ser.write(b'G28\n')
ser.write(b'G28')
ser.write("G28")

 have tried all these combinations, and I have also added:

time.sleep(5)

along with the relevant import statement for the time module at the top of my file. I added this line of code between my ser declaration and my ser.write function call.

I have also tried adding:

ser.close()

to see if that would make a difference but it has not, as I know this is best practice anyway.

No matter what combination of this code I used, when I run my python script my printer seems to restart (the screen changes from the home page to the opening wanhao logo and back to the home page)

I look forward to any help anyone can give me in regards to my code and what I may be doing wrong. 

read_potentiometer

 read_potentiometer.ino

import serial

import time

 # set up the serial line

ser = serial.Serial('COM3', 9600)

time.sleep(2)

# Read and record the data

data =[]                       # empty list to store the data

for i in range(50):

    b = ser.readline()         # read a byte string

    string_n = b.decode()  # decode byte string into Unicode  

    string = string_n.rstrip() # remove \n and \r

    flt = float(string)        # convert string to float

    print(flt)

    data.append(flt)           # add to the end of data list

    time.sleep(0.1)            # wait (sleep) 0.1 seconds

ser.close()


read_potentiometer.ino

// potentiometer_read.ino

// reads a potentiometer and sends value over serial

int sensorPin = A0;  // The potentiometer on pin 0                  

int ledPin = 13;     // The LED is connected on pin 13

int sensorValue;     // variable to stores data


void setup() // runs once when the sketch starts

{

  // make the LED pin (pin 13) an output pin

  pinMode(ledPin, OUTPUT);


  // initialize serial communication

  Serial.begin(9600);

}


void loop() // runs repeatedly after setup() finishes

{

  sensorValue = analogRead(sensorPin);  // read pin A0   

  Serial.println(sensorValue);         // send data to serial


  if (sensorValue < 500) {            // less than 500?

    digitalWrite(ledPin, LOW); }     // Turn the LED off


  else {                               // greater than 500?

    digitalWrite(ledPin, HIGH); }     // Keep the LED on


  delay(100);             // Pause 100 milliseconds

}

Nov 26, 2020

How PWM works | Controlling a DC motor with a homemade circuit

How PWM works | Controlling a DC motor with a homemade circuit

https://jlcpcb.com



Nov 25, 2020

read/write

Read/Write

===========================

i = 1

while i < 600:

  print(i)

  i += 100

else:

  #print("i is no longer less than 6")

  print(i)

================================= 

#for x in range(1,6,2):

#for x in range(1,6):                

# print(x)

=============================

 def my_function(): 

   print("Hello from a function")

 my_function()

====================================

 f = open("demofile.txt", "r")

 print(f.read())

=======================================

f = open("demofile2.txt", "a")

f.write("Now the file has more content!")

f.close()

#open and read the file after the appending:

f = open("demofile2.txt", "r")

print(f.read()) 

============================================