3D打印耗材直径的检测方案
本文主要讨论3D打印耗材直径的检测,前期所有的数据将由单片机呈现,后期将考虑加入klipper固件。 目前主流的方案有两种,一种是线性CCD检测,一种是基于霍尔检测。
霍尔检测
采用俩个49E
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 void setup () { pinMode(A0, INPUT); pinMode(A1, INPUT); Serial.begin(115200 ); } int mi15 = 118 ; int mi20 = 138 ; void loop () { int sum = 0 ; int count = 8 ; for (int i = 0 ; i < count; i++) { int a = analogRead(A0); int b = analogRead(A1); sum += (a - b); delay(5 ); } int average = sum / count; if (average < 90 ) { Serial.println("none" ); } else if (average > 160 ) { Serial.println("out" ); } else { float mmValue = 0 ; if (average >= mi15 && average <= mi20) { mmValue = 1.5 + (float (average - mi15) / (mi20 - mi15)) * (2.0 - 1.5 ); } Serial.print("毫米值: " ); Serial.println(mmValue); } }
目前存在问题,变化幅度小,分辨率低
霍尔检测修正 增加差分放大,放大4.7倍,OUT引脚读取
测试代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 #define READ_COUNT 5 const float VALUE_0_0MM = 222.0 ; const float VALUE_1_5MM = 382.0 ; const float VALUE_2_0MM = 440.0 ; void setup () { Serial.begin(9600 ); } void loop () { float analogValueA0 = readAverage(A0); float mmValueA0 = calculateMM(analogValueA0); float analogValueA1 = readAverage(A2); float mmValueA1 = calculateMM(analogValueA1); float analogValueA2 = readAverage(A3); float mmValueA2 = calculateMM(analogValueA2); Serial.print("A0 - Analog: " ); Serial.print(analogValueA0); Serial.print(" mm: " ); Serial.println(mmValueA0); Serial.print("A2 - Analog: " ); Serial.print(analogValueA1); Serial.print(" mm: " ); Serial.println(mmValueA1); Serial.print("A3 - Analog: " ); Serial.print(analogValueA2); Serial.print(" mm: " ); Serial.println(mmValueA2); delay(100 ); } float readAverage (int pin) { long sum = 0 ; for (int i = 0 ; i < READ_COUNT; i++) { sum += analogRead(pin); delay(10 ); } return sum / (float )READ_COUNT; } float calculateMM (float analogValue) { if (analogValue <= VALUE_0_0MM) return 0.0 ; if (analogValue >= VALUE_2_0MM) return 2.0 ; if (analogValue <= VALUE_1_5MM) { return (analogValue - VALUE_0_0MM) * (1.5 - 0.0 ) / (VALUE_1_5MM - VALUE_0_0MM); } else { return 1.5 + (analogValue - VALUE_1_5MM) * (2.0 - 1.5 ) / (VALUE_2_0MM - VALUE_1_5MM); } }
线性CCD检测 CCD的基本原理