Hi,
I am using teensy 4.1 to communicate with node-red, which is actually sending a large stream of data. I would also want my serial port to receive data.
My sort of Idea to send "START" command to initially to serial port using button and then same port would send me stream of data. and "STOP" command with another button to stop flow of data. I am stuck with my buttons not responding.
[
{
"id": "6ef4cd2b4815ca6f",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "Chart display ",
"env": []
},
{
"id": "b9b6c2061dd9470b",
"type": "function",
"z": "6ef4cd2b4815ca6f",
"d": true,
"name": "function 1",
"func": " var dataArray = msg.payload.split(\",\");\n var x = parseFloat(dataArray[0]);\n var y = parseFloat(dataArray[1]);\n var z = parseFloat(dataArray[2]);\n\nvar formattedData = [{\n \"series\": [\"x\", \"y\", \"y1\"],\n \"data\": [[{ \"x\": x, \"y\": y, \"y1\": z}]],\n \"label\": [\"\"]\n}];\n\n// Assign the formatted data to msg.payload\nmsg.payload = formattedData;\n\n// Return the modified message\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 720,
"y": 40,
"wires": [
[]
]
},
{
"id": "5c112154cfdce7cb",
"type": "function",
"z": "6ef4cd2b4815ca6f",
"name": "Process Data",
"func": "var dataArray = msg.payload.split(\",\");\nvar x = parseFloat(dataArray[0]);\nvar y = parseFloat(dataArray[1]);\nvar z = parseFloat(dataArray[2]);\n\nvar formattedData = {\n dataset1: [{ \"x\": x, \"y\": y }],\n dataset2: [{ \"x\": x, \"y\": z }]\n};\n\nmsg.payload = formattedData;\n\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 380,
"y": 160,
"wires": [
[
"ef6fa9b2.41d1d8"
]
]
},
{
"id": "e4b0f7ec.d9cfd8",
"type": "ui_button",
"z": "6ef4cd2b4815ca6f",
"name": "",
"group": "7194439235dd2c51",
"order": 2,
"width": 2,
"height": 2,
"passthru": false,
"label": "RUN/STOP",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "toggle",
"payloadType": "str",
"topic": "",
"topicType": "str",
"x": 150,
"y": 100,
"wires": [
[
"85f4b0a5.2d82b"
]
]
},
{
"id": "85f4b0a5.2d82b",
"type": "function",
"z": "6ef4cd2b4815ca6f",
"name": "Control Serial",
"func": "if (context.get('serialActive') === undefined) {\n context.set('serialActive', false);\n}\n\nvar serialActive = context.get('serialActive');\n\nif (msg.payload === 'toggle') {\n serialActive = !serialActive;\n context.set('serialActive', serialActive);\n}\n\nif (serialActive) {\n return [{payload: 'open'}, {payload: 'close'}];\n} else {\n return [{payload: 'close'}, {payload: 'open'}];\n}",
"outputs": 2,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 100,
"wires": [
[],
[]
]
},
{
"id": "ef6fa9b2.41d1d8",
"type": "ui_template",
"z": "6ef4cd2b4815ca6f",
"group": "7194439235dd2c51",
"name": "",
"order": 1,
"width": 0,
"height": 0,
"format": "<div>\n <canvas id=\"myChart\" width=\"400\" height=\"400\"></canvas>\n</div>\n<script src=\"https://cdn.jsdelivr.net/npm/chart.js\"></script>\n<script>\n (function(scope) {\n const initialData = {\n datasets: [{\n label: 'Current (I)',\n data: [],\n borderColor: 'rgba(255, 99, 132, 1)',\n backgroundColor: 'rgba(255, 99, 132, 0.2)',\n yAxisID: 'y',\n parsing: {\n xAxisKey: 'x',\n yAxisKey: 'y'\n }\n }, {\n label: 'Power (P)',\n data: [],\n borderColor: 'rgba(54, 162, 235, 1)',\n backgroundColor: 'rgba(54, 162, 235, 0.2)',\n yAxisID: 'y1',\n parsing: {\n xAxisKey: 'x',\n yAxisKey: 'y'\n }\n }]\n };\n\n const config = {\n type: 'line',\n data: initialData,\n options: {\n responsive: true,\n plugins: {\n title: {\n display: true,\n text: 'SOLAR SIMULTAOR PLOT ',\n font: {\n size: 20\n }\n }\n },\n scales: {\n x: {\n type: 'linear',\n position: 'bottom',\n title: {\n display: true,\n text: 'Voltage (V)',\n font: {\n size: 16\n }\n }\n },\n y: {\n type: 'linear',\n display: true,\n position: 'left',\n title: {\n display: true,\n text: 'Current (I)',\n font: {\n size: 16\n }\n }\n },\n y1: {\n type: 'linear',\n display: true,\n position: 'right',\n grid: {\n drawOnChartArea: false\n },\n title: {\n display: true,\n text: 'Power (P)',\n font: {\n size: 16\n }\n }\n }\n }\n }\n };\n\n const myChart = new Chart(\n document.getElementById('myChart'),\n config\n );\n\n scope.$watch('msg.payload', function(payload) {\n if (payload) {\n myChart.data.datasets[0].data = payload.dataset1 || myChart.data.datasets[0].data;\n myChart.data.datasets[1].data = payload.dataset2 || myChart.data.datasets[1].data;\n myChart.update();\n }\n });\n })(scope);\n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 540,
"y": 160,
"wires": [
[]
]
},
{
"id": "e17b27fb.0fd95",
"type": "function",
"z": "6ef4cd2b4815ca6f",
"name": "Format to CSV",
"func": "var timestamp = new Date().toISOString();\nvar dataArray = msg.payload.split(',');\nvar voltage = parseFloat(dataArray[0]);\nvar current \nvar csvData = `${timestamp},${dataArray.join(',')}`;\n\nreturn {\n filename: 'F:\\Node-red files\\values.csv',\n payload: csvData\n};",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 220,
"wires": [
[
"9b2f4b5f.f54f68"
]
]
},
{
"id": "9b2f4b5f.f54f68",
"type": "file",
"z": "6ef4cd2b4815ca6f",
"name": "Save to CSV",
"filename": "/path/to/save/data.csv",
"appendNewline": true,
"createDir": false,
"overwriteFile": "false",
"encoding": "none",
"x": 550,
"y": 220,
"wires": [
[]
]
},
{
"id": "2e507f5d.1e8a2a",
"type": "ui_button",
"z": "6ef4cd2b4815ca6f",
"name": "Start/Stop Recording",
"group": "7194439235dd2c51",
"order": 4,
"width": 2,
"height": 2,
"passthru": false,
"label": "Start Recording",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "toggle",
"payloadType": "str",
"topic": "",
"topicType": "str",
"x": 140,
"y": 220,
"wires": [
[
"e17b27fb.0fd95"
]
]
},
{
"id": "534988724f245eea",
"type": "serial in",
"z": "6ef4cd2b4815ca6f",
"name": "",
"serial": "6d118033428a6ddb",
"x": 170,
"y": 160,
"wires": [
[
"5c112154cfdce7cb",
"e17b27fb.0fd95"
]
]
},
{
"id": "633dd93a1d13c294",
"type": "ui_spacer",
"z": "6ef4cd2b4815ca6f",
"name": "spacer",
"group": "33f05c93310ec062",
"order": 1,
"width": 12,
"height": 1
},
{
"id": "7f62f5bd1e8d72db",
"type": "ui_spacer",
"z": "6ef4cd2b4815ca6f",
"name": "spacer",
"group": "33f05c93310ec062",
"order": 3,
"width": 12,
"height": 1
},
{
"id": "f8d3482f047bd6ce",
"type": "ui_spacer",
"z": "6ef4cd2b4815ca6f",
"name": "spacer",
"group": "33f05c93310ec062",
"order": 4,
"width": 3,
"height": 1
},
{
"id": "486f516b33997d3a",
"type": "ui_spacer",
"z": "6ef4cd2b4815ca6f",
"name": "spacer",
"group": "33f05c93310ec062",
"order": 5,
"width": 7,
"height": 1
},
{
"id": "8e18e686c208c2ba",
"type": "ui_spacer",
"z": "6ef4cd2b4815ca6f",
"name": "spacer",
"group": "33f05c93310ec062",
"order": 6,
"width": 3,
"height": 1
},
{
"id": "83adaecf80503ee9",
"type": "ui_spacer",
"z": "6ef4cd2b4815ca6f",
"name": "spacer",
"group": "33f05c93310ec062",
"order": 7,
"width": 7,
"height": 1
},
{
"id": "3238ae01e93a545f",
"type": "ui_spacer",
"z": "6ef4cd2b4815ca6f",
"name": "spacer",
"group": "7194439235dd2c51",
"order": 5,
"width": 9,
"height": 1
},
{
"id": "90c934cfa154af21",
"type": "ui_spacer",
"z": "6ef4cd2b4815ca6f",
"name": "spacer",
"group": "7194439235dd2c51",
"order": 6,
"width": 9,
"height": 1
},
{
"id": "7194439235dd2c51",
"type": "ui_group",
"name": "SS",
"tab": "b6867d794c44ccf6",
"order": 1,
"disp": true,
"width": 15,
"collapse": false,
"className": ""
},
{
"id": "6d118033428a6ddb",
"type": "serial-port",
"name": "Data Stream",
"serialport": "COM11",
"serialbaud": "9600",
"databits": "8",
"parity": "none",
"stopbits": "1",
"waitfor": "",
"dtr": "none",
"rts": "none",
"cts": "none",
"dsr": "none",
"newline": "\\n",
"bin": "false",
"out": "char",
"addchar": "",
"responsetimeout": "10000"
},
{
"id": "33f05c93310ec062",
"type": "ui_group",
"name": "Test Tab",
"tab": "",
"order": 1,
"disp": true,
"width": "12",
"collapse": false,
"className": ""
},
{
"id": "b6867d794c44ccf6",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]