Initial commit

This commit is contained in:
2019-02-24 08:10:26 +01:00
commit d1582cabd0
6 changed files with 127 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env python
from pymodbus.client.sync import ModbusSerialClient
import time
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
client = ModbusSerialClient(method='rtu', port='/dev/serial/by-id/usb-FTDI_TTL232R_FTF48YOZ-if00-port0', timeout=0.02, baudrate=115200)
client.connect()
time.sleep(1)
log.debug("Read input registers")
start = time.time()
found = 0
for n in range(256):
rr = client.read_input_registers(1, 1, unit=n)
found += not rr.isError()
print(rr)
print(time.time() - start, found)
client.close()
+12
View File
@@ -0,0 +1,12 @@
Fails:
* r1 was supposed to be a pullup
* programming/icsp header is broken
Prog
====
* avrdude -c avrisp -b 19200 -p m328p -P /dev/ttyUSB5 -vvv
* avrdude -pm328pb -cstk500v1 -P/dev/ttyUSB5 -b19200 -e -Uefuse:w:0xf5:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xFF:m
* avrdude -pm328pb -cstk500v1 -P/dev/ttyUSB5 -b19200 -Uflash:w:/home/informatic/.arduino15/packages/arduino/hardware/avr/1.6.8/bootloaders/optiboot/optiboot_atmega328.hex:i -Ulock:w:0x0F:m
+2
View File
@@ -0,0 +1,2 @@
.pioenvs
.piolibdeps
+36
View File
@@ -0,0 +1,36 @@
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.
The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".
For example, see how can be organized `Foo` and `Bar` libraries:
|--lib
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |- readme.txt --> THIS FILE
|- platformio.ini
|--src
|- main.c
Then in `src/main.c` you should use:
#include <Foo.h>
#include <Bar.h>
// rest H/C/CPP code
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
More information about PlatformIO Library Dependency Finder
- http://docs.platformio.org/page/librarymanager/ldf.html
+21
View File
@@ -0,0 +1,21 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_port = /dev/serial/by-id/usb-FTDI_TTL232R_FTF48YOZ-if00-port0
upload_port = /dev/serial/by-id/usb-FTDI_TTL232R_FTF48YOZ-if00-port0
targets = upload, monitor
monitor_baud = 115200
lib_deps =
https://github.com/yaacov/ArduinoModbusSlave/archive/03e0182795fee5e7025c14c5817cac835f760eae.zip
+35
View File
@@ -0,0 +1,35 @@
#include <ModbusSlave.h>
#include <EEPROM.h>
// explicitly set stream to use the Serial serialport
Modbus modbus(Serial, 1, 3); // stream = Serial, slave id = 1, rs485 control-pin = 8
void setup() {
pinMode(13, OUTPUT);
Serial.begin(115200);
Serial.print("Initializing! ");
for (int i = 0; i < 16; i++) {
Serial.print(EEPROM.read(1));
Serial.print(" ");
}
Serial.println();
modbus.cbVector[CB_READ_INPUT_REGISTERS] = ReadAnalogIn;
modbus.begin(115200);
}
void loop() {
modbus.poll();
digitalWrite(13, (millis() / 200) % 2);
}
// Handel Read Input Registers (FC=04)
uint8_t ReadAnalogIn(uint8_t fc, uint16_t address, uint16_t length) {
// write registers into the answer buffer
for (int i = 0; i < length; i++) {
modbus.writeRegisterToBuffer(i, analogRead(address + i));
}
return STATUS_OK;
}